macro_rules! magic_number {
    ($name:ident, $value:expr) => {
        const $name: u32 = $value;
    };
}
magic_number!(KEYC_VI, 0x20000000);
magic_number!(KEYC_SENT, 0x40000000);
magic_number!(CLIENT_ACTIVEPANE, 0x80000000);

extern "C" {
    pub type event_base;
    pub type evbuffer;
    pub type bufferevent_ops;
    pub type args;
    pub type tmuxpeer;
    pub type hyperlinks;
    pub type screen_write_cline;
    pub type screen_sel;
    pub type screen_titles;
    pub type environ;
    pub type options;
    pub type format_tree;
    pub type input_ctx;
    pub type cmds;
    pub type tty_key;
    pub type tty_code;
    pub type format_job_tree;
    pub type control_state;
    pub type cmdq_list;
    pub type cmdq_item;
    pub type screen_write_citem;
    fn free(_: *mut ());
    fn memcpy(_: *mut (), _: *const (), _: u64) -> *mut ();
    fn memset(_: *mut (), _: i32, _: u64) -> *mut ();
    fn format_create(_: *mut client, _: *mut cmdq_item, _: i32, _: i32) -> *mut format_tree;
    fn format_free(_: *mut format_tree);
    fn format_expand_time(_: *mut format_tree, _: *const i8) -> *mut i8;
    fn format_create_defaults(
        _: *mut cmdq_item,
        _: *mut client,
        _: *mut session,
        _: *mut winlink,
        _: *mut window_pane,
    ) -> *mut format_tree;
    fn format_defaults(
        _: *mut format_tree,
        _: *mut client,
        _: *mut session,
        _: *mut winlink,
        _: *mut window_pane,
    );
    fn format_draw(
        _: *mut screen_write_ctx,
        _: *const grid_cell,
        _: u_int,
        _: *const i8,
        _: *mut style_ranges,
        _: i32,
    );
    fn options_get_string(_: *mut options, _: *const i8) -> *const i8;
    fn options_get_number(_: *mut options, _: *const i8) -> i64;
    fn tty_window_offset(
        _: *mut tty,
        _: *mut u_int,
        _: *mut u_int,
        _: *mut u_int,
        _: *mut u_int,
    ) -> i32;
    fn tty_reset(_: *mut tty);
    fn tty_cursor(_: *mut tty, _: u_int, _: u_int);
    fn tty_puts(_: *mut tty, _: *const i8);
    fn tty_cell(
        _: *mut tty,
        _: *const grid_cell,
        _: *const grid_cell,
        _: *mut colour_palette,
        _: *mut hyperlinks,
    );
    fn tty_update_mode(_: *mut tty, _: i32, _: *mut screen);
    fn tty_draw_line(
        _: *mut tty,
        _: *mut screen,
        _: u_int,
        _: u_int,
        _: u_int,
        _: u_int,
        _: u_int,
        _: *const grid_cell,
        _: *mut colour_palette,
    );
    fn tty_sync_start(_: *mut tty);
    fn tty_default_colours(_: *mut grid_cell, _: *mut window_pane);
    fn tty_term_has(_: *mut tty_term, _: tty_code_code) -> i32;
    fn tty_acs_double_borders(_: i32) -> *const utf8_data;
    fn tty_acs_heavy_borders(_: i32) -> *const utf8_data;
    static mut marked_pane: cmd_find_state;
    fn server_is_marked(_: *mut session, _: *mut winlink, _: *mut window_pane) -> i32;
    fn server_client_get_pane(_: *mut client) -> *mut window_pane;
    fn status_line_size(_: *mut client) -> u_int;
    fn status_redraw(_: *mut client) -> i32;
    fn status_message_redraw(_: *mut client) -> i32;
    fn status_prompt_redraw(_: *mut client) -> i32;
    fn screen_write_start(_: *mut screen_write_ctx, _: *mut screen);
    fn screen_write_stop(_: *mut screen_write_ctx);
    fn screen_write_cursormove(_: *mut screen_write_ctx, _: i32, _: i32, _: i32);
    fn screen_write_cell(_: *mut screen_write_ctx, _: *const grid_cell);
    fn grid_compare(_: *mut grid, _: *mut grid) -> i32;
    fn window_pane_index(_: *mut window_pane, _: *mut u_int) -> i32;
    static grid_default_cell: grid_cell;
    fn screen_free(_: *mut screen);
    fn screen_init(_: *mut screen, _: u_int, _: u_int, _: u_int);
    fn window_pane_show_scrollbar(_: *mut window_pane, _: i32) -> i32;
    fn window_pane_visible(_: *mut window_pane) -> i32;
    fn window_pane_mode(_: *mut window_pane) -> i32;
    fn window_copy_get_current_offset(_: *mut window_pane, _: *mut u_int, _: *mut u_int) -> i32;
    fn log_debug(_: *const i8, _: ...);
    fn style_add(_: *mut grid_cell, _: *mut options, _: *const i8, _: *mut format_tree);
    fn style_apply(_: *mut grid_cell, _: *mut options, _: *const i8, _: *mut format_tree);
    fn utf8_copy(_: *mut utf8_data, _: *const utf8_data);
    fn utf8_set(_: *mut utf8_data, _: u_char);
}
pub type __u_char = u8;
pub type __u_short = u16;
pub type __u_int = u32;
pub type __uint8_t = u8;
pub type __uint64_t = u64;
pub type __pid_t = i32;
pub type __time_t = i64;
pub type __suseconds_t = i64;
pub type u_char = __u_char;
pub type u_short = __u_short;
pub type u_int = __u_int;
pub type pid_t = __pid_t;
pub type time_t = __time_t;
pub type size_t = u64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct timeval {
    pub tv_sec: __time_t,
    pub tv_usec: __suseconds_t,
}
pub type cc_t = u8;
pub type speed_t = u32;
pub type tcflag_t = u32;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct termios {
    pub c_iflag: tcflag_t,
    pub c_oflag: tcflag_t,
    pub c_cflag: tcflag_t,
    pub c_lflag: tcflag_t,
    pub c_line: cc_t,
    pub c_cc: [cc_t; 32],
    pub c_ispeed: speed_t,
    pub c_ospeed: speed_t,
}
pub type uint8_t = __uint8_t;
pub type uint64_t = __uint64_t;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event {
    pub ev_evcallback: event_callback,
    pub ev_timeout_pos: C2RustUnnamed_4,
    pub ev_fd: i32,
    pub ev_base: *mut event_base,
    pub ev_: C2RustUnnamed,
    pub ev_events: i16,
    pub ev_res: i16,
    pub ev_timeout: timeval,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed {
    pub ev_io: C2RustUnnamed_2,
    pub ev_signal: C2RustUnnamed_0,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_0 {
    pub ev_signal_next: C2RustUnnamed_1,
    pub ev_ncalls: i16,
    pub ev_pncalls: *mut i16,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_1 {
    pub le_next: *mut event,
    pub le_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_2 {
    pub ev_io_next: C2RustUnnamed_3,
    pub ev_timeout: timeval,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_3 {
    pub le_next: *mut event,
    pub le_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_4 {
    pub ev_next_with_common_timeout: C2RustUnnamed_5,
    pub min_heap_idx: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_5 {
    pub tqe_next: *mut event,
    pub tqe_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event_callback {
    pub evcb_active_next: C2RustUnnamed_7,
    pub evcb_flags: i16,
    pub evcb_pri: uint8_t,
    pub evcb_closure: uint8_t,
    pub evcb_cb_union: C2RustUnnamed_6,
    pub evcb_arg: *mut (),
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_6 {
    pub evcb_callback: Option<unsafe extern "C" fn(i32, i16, *mut ()) -> ()>,
    pub evcb_selfcb: Option<unsafe extern "C" fn(*mut event_callback, *mut ()) -> ()>,
    pub evcb_evfinalize: Option<unsafe extern "C" fn(*mut event, *mut ()) -> ()>,
    pub evcb_cbfinalize: Option<unsafe extern "C" fn(*mut event_callback, *mut ()) -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_7 {
    pub tqe_next: *mut event_callback,
    pub tqe_prev: *mut *mut event_callback,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct bufferevent {
    pub ev_base: *mut event_base,
    pub be_ops: *const bufferevent_ops,
    pub ev_read: event,
    pub ev_write: event,
    pub input: *mut evbuffer,
    pub output: *mut evbuffer,
    pub wm_read: event_watermark,
    pub wm_write: event_watermark,
    pub readcb: bufferevent_data_cb,
    pub writecb: bufferevent_data_cb,
    pub errorcb: bufferevent_event_cb,
    pub cbarg: *mut (),
    pub timeout_read: timeval,
    pub timeout_write: timeval,
    pub enabled: i16,
}
pub type bufferevent_event_cb =
    Option<unsafe extern "C" fn(*mut bufferevent, i16, *mut ()) -> ()>;
pub type bufferevent_data_cb =
    Option<unsafe extern "C" fn(*mut bufferevent, *mut ()) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event_watermark {
    pub low: size_t,
    pub high: size_t,
}
pub type bitstr_t = u8;
pub type msgtype = u32;
pub const MSG_READ_CANCEL: msgtype = 307;
pub const MSG_WRITE_CLOSE: msgtype = 306;
pub const MSG_WRITE_READY: msgtype = 305;
pub const MSG_WRITE: msgtype = 304;
pub const MSG_WRITE_OPEN: msgtype = 303;
pub const MSG_READ_DONE: msgtype = 302;
pub const MSG_READ: msgtype = 301;
pub const MSG_READ_OPEN: msgtype = 300;
pub const MSG_FLAGS: msgtype = 218;
pub const MSG_EXEC: msgtype = 217;
pub const MSG_WAKEUP: msgtype = 216;
pub const MSG_UNLOCK: msgtype = 215;
pub const MSG_SUSPEND: msgtype = 214;
pub const MSG_OLDSTDOUT: msgtype = 213;
pub const MSG_OLDSTDIN: msgtype = 212;
pub const MSG_OLDSTDERR: msgtype = 211;
pub const MSG_SHUTDOWN: msgtype = 210;
pub const MSG_SHELL: msgtype = 209;
pub const MSG_RESIZE: msgtype = 208;
pub const MSG_READY: msgtype = 207;
pub const MSG_LOCK: msgtype = 206;
pub const MSG_EXITING: msgtype = 205;
pub const MSG_EXITED: msgtype = 204;
pub const MSG_EXIT: msgtype = 203;
pub const MSG_DETACHKILL: msgtype = 202;
pub const MSG_DETACH: msgtype = 201;
pub const MSG_COMMAND: msgtype = 200;
pub const MSG_IDENTIFY_TERMINFO: msgtype = 112;
pub const MSG_IDENTIFY_LONGFLAGS: msgtype = 111;
pub const MSG_IDENTIFY_STDOUT: msgtype = 110;
pub const MSG_IDENTIFY_FEATURES: msgtype = 109;
pub const MSG_IDENTIFY_CWD: msgtype = 108;
pub const MSG_IDENTIFY_CLIENTPID: msgtype = 107;
pub const MSG_IDENTIFY_DONE: msgtype = 106;
pub const MSG_IDENTIFY_ENVIRON: msgtype = 105;
pub const MSG_IDENTIFY_STDIN: msgtype = 104;
pub const MSG_IDENTIFY_OLDCWD: msgtype = 103;
pub const MSG_IDENTIFY_TTYNAME: msgtype = 102;
pub const MSG_IDENTIFY_TERM: msgtype = 101;
pub const MSG_IDENTIFY_FLAGS: msgtype = 100;
pub const MSG_VERSION: msgtype = 12;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client {
    pub name: *const i8,
    pub peer: *mut tmuxpeer,
    pub queue: *mut cmdq_list,
    pub windows: client_windows,
    pub control_state: *mut control_state,
    pub pause_age: u_int,
    pub pid: pid_t,
    pub fd: i32,
    pub out_fd: i32,
    pub event: event,
    pub retval: i32,
    pub creation_time: timeval,
    pub activity_time: timeval,
    pub last_activity_time: timeval,
    pub environ: *mut environ,
    pub jobs: *mut format_job_tree,
    pub title: *mut i8,
    pub path: *mut i8,
    pub cwd: *const i8,
    pub term_name: *mut i8,
    pub term_features: i32,
    pub term_type: *mut i8,
    pub term_caps: *mut *mut i8,
    pub term_ncaps: u_int,
    pub ttyname: *mut i8,
    pub tty: tty,
    pub written: size_t,
    pub discarded: size_t,
    pub redraw: size_t,
    pub repeat_timer: event,
    pub click_timer: event,
    pub click_button: u_int,
    pub click_event: mouse_event,
    pub status: status_line,
    pub flags: uint64_t,
    pub exit_type: C2RustUnnamed_30,
    pub exit_msgtype: msgtype,
    pub exit_session: *mut i8,
    pub exit_message: *mut i8,
    pub keytable: *mut key_table,
    pub last_key: key_code,
    pub redraw_panes: uint64_t,
    pub redraw_scrollbars: uint64_t,
    pub message_ignore_keys: i32,
    pub message_ignore_styles: i32,
    pub message_string: *mut i8,
    pub message_timer: event,
    pub prompt_string: *mut i8,
    pub prompt_buffer: *mut utf8_data,
    pub prompt_last: *mut i8,
    pub prompt_index: size_t,
    pub prompt_inputcb: prompt_input_cb,
    pub prompt_freecb: prompt_free_cb,
    pub prompt_data: *mut (),
    pub prompt_hindex: [u_int; 4],
    pub prompt_mode: C2RustUnnamed_27,
    pub prompt_saved: *mut utf8_data,
    pub prompt_flags: i32,
    pub prompt_type: prompt_type,
    pub prompt_cursor: i32,
    pub session: *mut session,
    pub last_session: *mut session,
    pub references: i32,
    pub pan_window: *mut (),
    pub pan_ox: u_int,
    pub pan_oy: u_int,
    pub overlay_check: overlay_check_cb,
    pub overlay_mode: overlay_mode_cb,
    pub overlay_draw: overlay_draw_cb,
    pub overlay_key: overlay_key_cb,
    pub overlay_free: overlay_free_cb,
    pub overlay_resize: overlay_resize_cb,
    pub overlay_data: *mut (),
    pub overlay_timer: event,
    pub files: client_files,
    pub clipboard_panes: *mut u_int,
    pub clipboard_npanes: u_int,
    pub entry: C2RustUnnamed_8,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_8 {
    pub tqe_next: *mut client,
    pub tqe_prev: *mut *mut client,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_files {
    pub rbh_root: *mut client_file,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_file {
    pub c: *mut client,
    pub peer: *mut tmuxpeer,
    pub tree: *mut client_files,
    pub references: i32,
    pub stream: i32,
    pub path: *mut i8,
    pub buffer: *mut evbuffer,
    pub event: *mut bufferevent,
    pub fd: i32,
    pub error: i32,
    pub closed: i32,
    pub cb: client_file_cb,
    pub data: *mut (),
    pub entry: C2RustUnnamed_9,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_9 {
    pub rbe_left: *mut client_file,
    pub rbe_right: *mut client_file,
    pub rbe_parent: *mut client_file,
    pub rbe_color: i32,
}
pub type client_file_cb = Option<
    unsafe extern "C" fn(*mut client, *const i8, i32, i32, *mut evbuffer, *mut ()) -> (),
>;
pub type overlay_resize_cb = Option<unsafe extern "C" fn(*mut client, *mut ()) -> ()>;
pub type overlay_free_cb = Option<unsafe extern "C" fn(*mut client, *mut ()) -> ()>;
pub type overlay_key_cb =
    Option<unsafe extern "C" fn(*mut client, *mut (), *mut key_event) -> i32>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_event {
    pub key: key_code,
    pub m: mouse_event,
    pub buf: *mut i8,
    pub len: size_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct mouse_event {
    pub valid: i32,
    pub ignore: i32,
    pub key: key_code,
    pub statusat: i32,
    pub statuslines: u_int,
    pub x: u_int,
    pub y: u_int,
    pub b: u_int,
    pub lx: u_int,
    pub ly: u_int,
    pub lb: u_int,
    pub ox: u_int,
    pub oy: u_int,
    pub s: i32,
    pub w: i32,
    pub wp: i32,
    pub sgr_type: u_int,
    pub sgr_b: u_int,
}
pub type key_code = u64;
pub type overlay_draw_cb =
    Option<unsafe extern "C" fn(*mut client, *mut (), *mut screen_redraw_ctx) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct screen_redraw_ctx {
    pub c: *mut client,
    pub statuslines: u_int,
    pub statustop: i32,
    pub pane_status: i32,
    pub pane_lines: pane_lines,
    pub pane_scrollbars: i32,
    pub pane_scrollbars_pos: i32,
    pub no_pane_gc: grid_cell,
    pub no_pane_gc_set: i32,
    pub sx: u_int,
    pub sy: u_int,
    pub ox: u_int,
    pub oy: u_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid_cell {
    pub data: utf8_data,
    pub attr: u_short,
    pub flags: u_char,
    pub fg: i32,
    pub bg: i32,
    pub us: i32,
    pub link: u_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct utf8_data {
    pub data: [u_char; 21],
    pub have: u_char,
    pub size: u_char,
    pub width: u_char,
}
pub type pane_lines = u32;
pub const PANE_LINES_NUMBER: pane_lines = 4;
pub const PANE_LINES_SIMPLE: pane_lines = 3;
pub const PANE_LINES_HEAVY: pane_lines = 2;
pub const PANE_LINES_DOUBLE: pane_lines = 1;
pub const PANE_LINES_SINGLE: pane_lines = 0;
pub type overlay_mode_cb = Option<
    unsafe extern "C" fn(*mut client, *mut (), *mut u_int, *mut u_int) -> *mut screen,
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct screen {
    pub title: *mut i8,
    pub path: *mut i8,
    pub titles: *mut screen_titles,
    pub grid: *mut grid,
    pub cx: u_int,
    pub cy: u_int,
    pub cstyle: screen_cursor_style,
    pub default_cstyle: screen_cursor_style,
    pub ccolour: i32,
    pub default_ccolour: i32,
    pub rupper: u_int,
    pub rlower: u_int,
    pub mode: i32,
    pub default_mode: i32,
    pub saved_cx: u_int,
    pub saved_cy: u_int,
    pub saved_grid: *mut grid,
    pub saved_cell: grid_cell,
    pub saved_flags: i32,
    pub tabs: *mut bitstr_t,
    pub sel: *mut screen_sel,
    pub write_list: *mut screen_write_cline,
    pub hyperlinks: *mut hyperlinks,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid {
    pub flags: i32,
    pub sx: u_int,
    pub sy: u_int,
    pub hscrolled: u_int,
    pub hsize: u_int,
    pub hlimit: u_int,
    pub linedata: *mut grid_line,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid_line {
    pub celldata: *mut grid_cell_entry,
    pub cellused: u_int,
    pub cellsize: u_int,
    pub extddata: *mut grid_extd_entry,
    pub extdsize: u_int,
    pub flags: i32,
    pub time: time_t,
}
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct grid_extd_entry {
    pub data: utf8_char,
    pub attr: u_short,
    pub flags: u_char,
    pub fg: i32,
    pub bg: i32,
    pub us: i32,
    pub link: u_int,
}
pub type utf8_char = u_int;
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct grid_cell_entry {
    pub c2rust_unnamed: C2RustUnnamed_10,
    pub flags: u_char,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_10 {
    pub offset: u_int,
    pub data: C2RustUnnamed_11,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_11 {
    pub attr: u_char,
    pub fg: u_char,
    pub bg: u_char,
    pub data: u_char,
}
pub type screen_cursor_style = u32;
pub const SCREEN_CURSOR_BAR: screen_cursor_style = 3;
pub const SCREEN_CURSOR_UNDERLINE: screen_cursor_style = 2;
pub const SCREEN_CURSOR_BLOCK: screen_cursor_style = 1;
pub const SCREEN_CURSOR_DEFAULT: screen_cursor_style = 0;
pub type overlay_check_cb = Option<
    unsafe extern "C" fn(
        *mut client,
        *mut (),
        u_int,
        u_int,
        u_int,
        *mut overlay_ranges,
    ) -> (),
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct overlay_ranges {
    pub px: [u_int; 3],
    pub nx: [u_int; 3],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct session {
    pub id: u_int,
    pub name: *mut i8,
    pub cwd: *const i8,
    pub creation_time: timeval,
    pub last_attached_time: timeval,
    pub activity_time: timeval,
    pub last_activity_time: timeval,
    pub lock_timer: event,
    pub curw: *mut winlink,
    pub lastw: winlink_stack,
    pub windows: winlinks,
    pub statusat: i32,
    pub statuslines: u_int,
    pub options: *mut options,
    pub flags: i32,
    pub attached: u_int,
    pub tio: *mut termios,
    pub environ: *mut environ,
    pub references: i32,
    pub gentry: C2RustUnnamed_13,
    pub entry: C2RustUnnamed_12,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_12 {
    pub rbe_left: *mut session,
    pub rbe_right: *mut session,
    pub rbe_parent: *mut session,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_13 {
    pub tqe_next: *mut session,
    pub tqe_prev: *mut *mut session,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlinks {
    pub rbh_root: *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlink {
    pub idx: i32,
    pub session: *mut session,
    pub window: *mut window,
    pub flags: i32,
    pub entry: C2RustUnnamed_16,
    pub wentry: C2RustUnnamed_15,
    pub sentry: C2RustUnnamed_14,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_14 {
    pub tqe_next: *mut winlink,
    pub tqe_prev: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_15 {
    pub tqe_next: *mut winlink,
    pub tqe_prev: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_16 {
    pub rbe_left: *mut winlink,
    pub rbe_right: *mut winlink,
    pub rbe_parent: *mut winlink,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window {
    pub id: u_int,
    pub latest: *mut (),
    pub name: *mut i8,
    pub name_event: event,
    pub name_time: timeval,
    pub alerts_timer: event,
    pub offset_timer: event,
    pub activity_time: timeval,
    pub active: *mut window_pane,
    pub last_panes: window_panes,
    pub panes: window_panes,
    pub lastlayout: i32,
    pub layout_root: *mut layout_cell,
    pub saved_layout_root: *mut layout_cell,
    pub old_layout: *mut i8,
    pub sx: u_int,
    pub sy: u_int,
    pub manual_sx: u_int,
    pub manual_sy: u_int,
    pub xpixel: u_int,
    pub ypixel: u_int,
    pub new_sx: u_int,
    pub new_sy: u_int,
    pub new_xpixel: u_int,
    pub new_ypixel: u_int,
    pub fill_character: *mut utf8_data,
    pub flags: i32,
    pub alerts_queued: i32,
    pub alerts_entry: C2RustUnnamed_19,
    pub options: *mut options,
    pub references: u_int,
    pub winlinks: C2RustUnnamed_18,
    pub entry: C2RustUnnamed_17,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_17 {
    pub rbe_left: *mut window,
    pub rbe_right: *mut window,
    pub rbe_parent: *mut window,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_18 {
    pub tqh_first: *mut winlink,
    pub tqh_last: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_19 {
    pub tqe_next: *mut window,
    pub tqe_prev: *mut *mut window,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct layout_cell {
    pub type_0: layout_type,
    pub parent: *mut layout_cell,
    pub sx: u_int,
    pub sy: u_int,
    pub xoff: u_int,
    pub yoff: u_int,
    pub wp: *mut window_pane,
    pub cells: layout_cells,
    pub entry: C2RustUnnamed_20,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_20 {
    pub tqe_next: *mut layout_cell,
    pub tqe_prev: *mut *mut layout_cell,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct layout_cells {
    pub tqh_first: *mut layout_cell,
    pub tqh_last: *mut *mut layout_cell,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane {
    pub id: u_int,
    pub active_point: u_int,
    pub window: *mut window,
    pub options: *mut options,
    pub layout_cell: *mut layout_cell,
    pub saved_layout_cell: *mut layout_cell,
    pub sx: u_int,
    pub sy: u_int,
    pub xoff: u_int,
    pub yoff: u_int,
    pub flags: i32,
    pub sb_slider_y: u_int,
    pub sb_slider_h: u_int,
    pub argc: i32,
    pub argv: *mut *mut i8,
    pub shell: *mut i8,
    pub cwd: *mut i8,
    pub pid: pid_t,
    pub tty: [i8; 32],
    pub status: i32,
    pub dead_time: timeval,
    pub fd: i32,
    pub event: *mut bufferevent,
    pub offset: window_pane_offset,
    pub base_offset: size_t,
    pub resize_queue: window_pane_resizes,
    pub resize_timer: event,
    pub ictx: *mut input_ctx,
    pub cached_gc: grid_cell,
    pub cached_active_gc: grid_cell,
    pub palette: colour_palette,
    pub pipe_fd: i32,
    pub pipe_event: *mut bufferevent,
    pub pipe_offset: window_pane_offset,
    pub screen: *mut screen,
    pub base: screen,
    pub status_screen: screen,
    pub status_size: size_t,
    pub modes: C2RustUnnamed_24,
    pub searchstr: *mut i8,
    pub searchregex: i32,
    pub border_gc_set: i32,
    pub border_gc: grid_cell,
    pub control_bg: i32,
    pub control_fg: i32,
    pub scrollbar_style: style,
    pub entry: C2RustUnnamed_23,
    pub sentry: C2RustUnnamed_22,
    pub tree_entry: C2RustUnnamed_21,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_21 {
    pub rbe_left: *mut window_pane,
    pub rbe_right: *mut window_pane,
    pub rbe_parent: *mut window_pane,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_22 {
    pub tqe_next: *mut window_pane,
    pub tqe_prev: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_23 {
    pub tqe_next: *mut window_pane,
    pub tqe_prev: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style {
    pub gc: grid_cell,
    pub ignore: i32,
    pub fill: i32,
    pub align: style_align,
    pub list: style_list,
    pub range_type: style_range_type,
    pub range_argument: u_int,
    pub range_string: [i8; 16],
    pub width: i32,
    pub pad: i32,
    pub default_type: style_default_type,
}
pub type style_default_type = u32;
pub const STYLE_DEFAULT_POP: style_default_type = 2;
pub const STYLE_DEFAULT_PUSH: style_default_type = 1;
pub const STYLE_DEFAULT_BASE: style_default_type = 0;
pub type style_range_type = u32;
pub const STYLE_RANGE_USER: style_range_type = 6;
pub const STYLE_RANGE_SESSION: style_range_type = 5;
pub const STYLE_RANGE_WINDOW: style_range_type = 4;
pub const STYLE_RANGE_PANE: style_range_type = 3;
pub const STYLE_RANGE_RIGHT: style_range_type = 2;
pub const STYLE_RANGE_LEFT: style_range_type = 1;
pub const STYLE_RANGE_NONE: style_range_type = 0;
pub type style_list = u32;
pub const STYLE_LIST_RIGHT_MARKER: style_list = 4;
pub const STYLE_LIST_LEFT_MARKER: style_list = 3;
pub const STYLE_LIST_FOCUS: style_list = 2;
pub const STYLE_LIST_ON: style_list = 1;
pub const STYLE_LIST_OFF: style_list = 0;
pub type style_align = u32;
pub const STYLE_ALIGN_ABSOLUTE_CENTRE: style_align = 4;
pub const STYLE_ALIGN_RIGHT: style_align = 3;
pub const STYLE_ALIGN_CENTRE: style_align = 2;
pub const STYLE_ALIGN_LEFT: style_align = 1;
pub const STYLE_ALIGN_DEFAULT: style_align = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_24 {
    pub tqh_first: *mut window_mode_entry,
    pub tqh_last: *mut *mut window_mode_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_mode_entry {
    pub wp: *mut window_pane,
    pub swp: *mut window_pane,
    pub mode: *const window_mode,
    pub data: *mut (),
    pub screen: *mut screen,
    pub prefix: u_int,
    pub entry: C2RustUnnamed_25,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_25 {
    pub tqe_next: *mut window_mode_entry,
    pub tqe_prev: *mut *mut window_mode_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_mode {
    pub name: *const i8,
    pub default_format: *const i8,
    pub init: Option<
        unsafe extern "C" fn(*mut window_mode_entry, *mut cmd_find_state, *mut args) -> *mut screen,
    >,
    pub free: Option<unsafe extern "C" fn(*mut window_mode_entry) -> ()>,
    pub resize: Option<unsafe extern "C" fn(*mut window_mode_entry, u_int, u_int) -> ()>,
    pub update: Option<unsafe extern "C" fn(*mut window_mode_entry) -> ()>,
    pub key: Option<
        unsafe extern "C" fn(
            *mut window_mode_entry,
            *mut client,
            *mut session,
            *mut winlink,
            key_code,
            *mut mouse_event,
        ) -> (),
    >,
    pub key_table: Option<unsafe extern "C" fn(*mut window_mode_entry) -> *const i8>,
    pub command: Option<
        unsafe extern "C" fn(
            *mut window_mode_entry,
            *mut client,
            *mut session,
            *mut winlink,
            *mut args,
            *mut mouse_event,
        ) -> (),
    >,
    pub formats: Option<unsafe extern "C" fn(*mut window_mode_entry, *mut format_tree) -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_find_state {
    pub flags: i32,
    pub current: *mut cmd_find_state,
    pub s: *mut session,
    pub wl: *mut winlink,
    pub w: *mut window,
    pub wp: *mut window_pane,
    pub idx: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_offset {
    pub used: size_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct colour_palette {
    pub fg: i32,
    pub bg: i32,
    pub palette: *mut i32,
    pub default_palette: *mut i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_resizes {
    pub tqh_first: *mut window_pane_resize,
    pub tqh_last: *mut *mut window_pane_resize,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_resize {
    pub sx: u_int,
    pub sy: u_int,
    pub osx: u_int,
    pub osy: u_int,
    pub entry: C2RustUnnamed_26,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_26 {
    pub tqe_next: *mut window_pane_resize,
    pub tqe_prev: *mut *mut window_pane_resize,
}
pub type layout_type = u32;
pub const LAYOUT_WINDOWPANE: layout_type = 2;
pub const LAYOUT_TOPBOTTOM: layout_type = 1;
pub const LAYOUT_LEFTRIGHT: layout_type = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_panes {
    pub tqh_first: *mut window_pane,
    pub tqh_last: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlink_stack {
    pub tqh_first: *mut winlink,
    pub tqh_last: *mut *mut winlink,
}
pub type prompt_type = u32;
pub const PROMPT_TYPE_INVALID: prompt_type = 255;
pub const PROMPT_TYPE_WINDOW_TARGET: prompt_type = 3;
pub const PROMPT_TYPE_TARGET: prompt_type = 2;
pub const PROMPT_TYPE_SEARCH: prompt_type = 1;
pub const PROMPT_TYPE_COMMAND: prompt_type = 0;
pub type C2RustUnnamed_27 = u32;
pub const PROMPT_COMMAND: C2RustUnnamed_27 = 1;
pub const PROMPT_ENTRY: C2RustUnnamed_27 = 0;
pub type prompt_free_cb = Option<unsafe extern "C" fn(*mut ()) -> ()>;
pub type prompt_input_cb =
    Option<unsafe extern "C" fn(*mut client, *mut (), *const i8, i32) -> i32>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_table {
    pub name: *const i8,
    pub activity_time: timeval,
    pub key_bindings: key_bindings,
    pub default_key_bindings: key_bindings,
    pub references: u_int,
    pub entry: C2RustUnnamed_28,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_28 {
    pub rbe_left: *mut key_table,
    pub rbe_right: *mut key_table,
    pub rbe_parent: *mut key_table,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_bindings {
    pub rbh_root: *mut key_binding,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_binding {
    pub key: key_code,
    pub cmdlist: *mut cmd_list,
    pub note: *const i8,
    pub flags: i32,
    pub entry: C2RustUnnamed_29,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_29 {
    pub rbe_left: *mut key_binding,
    pub rbe_right: *mut key_binding,
    pub rbe_parent: *mut key_binding,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_list {
    pub references: i32,
    pub group: u_int,
    pub list: *mut cmds,
}
pub type C2RustUnnamed_30 = u32;
pub const CLIENT_EXIT_DETACH: C2RustUnnamed_30 = 2;
pub const CLIENT_EXIT_SHUTDOWN: C2RustUnnamed_30 = 1;
pub const CLIENT_EXIT_RETURN: C2RustUnnamed_30 = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct status_line {
    pub timer: event,
    pub screen: screen,
    pub active: *mut screen,
    pub references: i32,
    pub style: grid_cell,
    pub entries: [status_line_entry; 5],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct status_line_entry {
    pub expanded: *mut i8,
    pub ranges: style_ranges,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style_ranges {
    pub tqh_first: *mut style_range,
    pub tqh_last: *mut *mut style_range,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style_range {
    pub type_0: style_range_type,
    pub argument: u_int,
    pub string: [i8; 16],
    pub start: u_int,
    pub end: u_int,
    pub entry: C2RustUnnamed_31,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_31 {
    pub tqe_next: *mut style_range,
    pub tqe_prev: *mut *mut style_range,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct tty {
    pub client: *mut client,
    pub start_timer: event,
    pub clipboard_timer: event,
    pub last_requests: time_t,
    pub sx: u_int,
    pub sy: u_int,
    pub xpixel: u_int,
    pub ypixel: u_int,
    pub cx: u_int,
    pub cy: u_int,
    pub cstyle: screen_cursor_style,
    pub ccolour: i32,
    pub oflag: i32,
    pub oox: u_int,
    pub ooy: u_int,
    pub osx: u_int,
    pub osy: u_int,
    pub mode: i32,
    pub fg: i32,
    pub bg: i32,
    pub rlower: u_int,
    pub rupper: u_int,
    pub rleft: u_int,
    pub rright: u_int,
    pub event_in: event,
    pub in_0: *mut evbuffer,
    pub event_out: event,
    pub out: *mut evbuffer,
    pub timer: event,
    pub discarded: size_t,
    pub tio: termios,
    pub cell: grid_cell,
    pub last_cell: grid_cell,
    pub flags: i32,
    pub term: *mut tty_term,
    pub mouse_last_x: u_int,
    pub mouse_last_y: u_int,
    pub mouse_last_b: u_int,
    pub mouse_drag_flag: i32,
    pub mouse_scrolling_flag: i32,
    pub mouse_slider_mpos: i32,
    pub mouse_drag_update: Option<unsafe extern "C" fn(*mut client, *mut mouse_event) -> ()>,
    pub mouse_drag_release: Option<unsafe extern "C" fn(*mut client, *mut mouse_event) -> ()>,
    pub key_timer: event,
    pub key_tree: *mut tty_key,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct tty_term {
    pub name: *mut i8,
    pub tty: *mut tty,
    pub features: i32,
    pub acs: [[i8; 2]; 256],
    pub codes: *mut tty_code,
    pub flags: i32,
    pub entry: C2RustUnnamed_32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_32 {
    pub le_next: *mut tty_term,
    pub le_prev: *mut *mut tty_term,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_windows {
    pub rbh_root: *mut client_window,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_window {
    pub window: u_int,
    pub pane: *mut window_pane,
    pub sx: u_int,
    pub sy: u_int,
    pub entry: C2RustUnnamed_33,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_33 {
    pub rbe_left: *mut client_window,
    pub rbe_right: *mut client_window,
    pub rbe_parent: *mut client_window,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct screen_write_ctx {
    pub wp: *mut window_pane,
    pub s: *mut screen,
    pub flags: i32,
    pub init_ctx_cb: screen_write_init_ctx_cb,
    pub arg: *mut (),
    pub item: *mut screen_write_citem,
    pub scrolled: u_int,
    pub bg: u_int,
}
pub type screen_write_init_ctx_cb =
    Option<unsafe extern "C" fn(*mut screen_write_ctx, *mut tty_ctx) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct tty_ctx {
    pub s: *mut screen,
    pub redraw_cb: tty_ctx_redraw_cb,
    pub set_client_cb: tty_ctx_set_client_cb,
    pub arg: *mut (),
    pub cell: *const grid_cell,
    pub wrapped: i32,
    pub num: u_int,
    pub ptr: *mut (),
    pub ptr2: *mut (),
    pub allow_invisible_panes: i32,
    pub ocx: u_int,
    pub ocy: u_int,
    pub orupper: u_int,
    pub orlower: u_int,
    pub xoff: u_int,
    pub yoff: u_int,
    pub rxoff: u_int,
    pub ryoff: u_int,
    pub sx: u_int,
    pub sy: u_int,
    pub bg: u_int,
    pub defaults: grid_cell,
    pub palette: *mut colour_palette,
    pub bigger: i32,
    pub wox: u_int,
    pub woy: u_int,
    pub wsx: u_int,
    pub wsy: u_int,
}
pub type tty_ctx_set_client_cb = Option<unsafe extern "C" fn(*mut tty_ctx, *mut client) -> i32>;
pub type tty_ctx_redraw_cb = Option<unsafe extern "C" fn(*const tty_ctx) -> ()>;
pub type tty_code_code = u32;
pub const TTYC_XT: tty_code_code = 231;
pub const TTYC_VPA: tty_code_code = 230;
pub const TTYC_U8: tty_code_code = 229;
pub const TTYC_TSL: tty_code_code = 228;
pub const TTYC_TC: tty_code_code = 227;
pub const TTYC_SYNC: tty_code_code = 226;
pub const TTYC_SWD: tty_code_code = 225;
pub const TTYC_SS: tty_code_code = 224;
pub const TTYC_SXL: tty_code_code = 223;
pub const TTYC_SMXX: tty_code_code = 222;
pub const TTYC_SMULX: tty_code_code = 221;
pub const TTYC_SMUL: tty_code_code = 220;
pub const TTYC_SMSO: tty_code_code = 219;
pub const TTYC_SMOL: tty_code_code = 218;
pub const TTYC_SMKX: tty_code_code = 217;
pub const TTYC_SMCUP: tty_code_code = 216;
pub const TTYC_SMACS: tty_code_code = 215;
pub const TTYC_SITM: tty_code_code = 214;
pub const TTYC_SGR0: tty_code_code = 213;
pub const TTYC_SETULC1: tty_code_code = 212;
pub const TTYC_SETULC: tty_code_code = 211;
pub const TTYC_SETRGBF: tty_code_code = 210;
pub const TTYC_SETRGBB: tty_code_code = 209;
pub const TTYC_SETAL: tty_code_code = 208;
pub const TTYC_SETAF: tty_code_code = 207;
pub const TTYC_SETAB: tty_code_code = 206;
pub const TTYC_SE: tty_code_code = 205;
pub const TTYC_RMKX: tty_code_code = 204;
pub const TTYC_RMCUP: tty_code_code = 203;
pub const TTYC_RMACS: tty_code_code = 202;
pub const TTYC_RIN: tty_code_code = 201;
pub const TTYC_RI: tty_code_code = 200;
pub const TTYC_RGB: tty_code_code = 199;
pub const TTYC_REV: tty_code_code = 198;
pub const TTYC_RECT: tty_code_code = 197;
pub const TTYC_OP: tty_code_code = 196;
pub const TTYC_OL: tty_code_code = 195;
pub const TTYC_NOBR: tty_code_code = 194;
pub const TTYC_MS: tty_code_code = 193;
pub const TTYC_KUP7: tty_code_code = 192;
pub const TTYC_KUP6: tty_code_code = 191;
pub const TTYC_KUP5: tty_code_code = 190;
pub const TTYC_KUP4: tty_code_code = 189;
pub const TTYC_KUP3: tty_code_code = 188;
pub const TTYC_KUP2: tty_code_code = 187;
pub const TTYC_KRIT7: tty_code_code = 186;
pub const TTYC_KRIT6: tty_code_code = 185;
pub const TTYC_KRIT5: tty_code_code = 184;
pub const TTYC_KRIT4: tty_code_code = 183;
pub const TTYC_KRIT3: tty_code_code = 182;
pub const TTYC_KRIT2: tty_code_code = 181;
pub const TTYC_KRI: tty_code_code = 180;
pub const TTYC_KPRV7: tty_code_code = 179;
pub const TTYC_KPRV6: tty_code_code = 178;
pub const TTYC_KPRV5: tty_code_code = 177;
pub const TTYC_KPRV4: tty_code_code = 176;
pub const TTYC_KPRV3: tty_code_code = 175;
pub const TTYC_KPRV2: tty_code_code = 174;
pub const TTYC_KPP: tty_code_code = 173;
pub const TTYC_KNXT7: tty_code_code = 172;
pub const TTYC_KNXT6: tty_code_code = 171;
pub const TTYC_KNXT5: tty_code_code = 170;
pub const TTYC_KNXT4: tty_code_code = 169;
pub const TTYC_KNXT3: tty_code_code = 168;
pub const TTYC_KNXT2: tty_code_code = 167;
pub const TTYC_KNP: tty_code_code = 166;
pub const TTYC_KMOUS: tty_code_code = 165;
pub const TTYC_KLFT7: tty_code_code = 164;
pub const TTYC_KLFT6: tty_code_code = 163;
pub const TTYC_KLFT5: tty_code_code = 162;
pub const TTYC_KLFT4: tty_code_code = 161;
pub const TTYC_KLFT3: tty_code_code = 160;
pub const TTYC_KLFT2: tty_code_code = 159;
pub const TTYC_KIND: tty_code_code = 158;
pub const TTYC_KICH1: tty_code_code = 157;
pub const TTYC_KIC7: tty_code_code = 156;
pub const TTYC_KIC6: tty_code_code = 155;
pub const TTYC_KIC5: tty_code_code = 154;
pub const TTYC_KIC4: tty_code_code = 153;
pub const TTYC_KIC3: tty_code_code = 152;
pub const TTYC_KIC2: tty_code_code = 151;
pub const TTYC_KHOME: tty_code_code = 150;
pub const TTYC_KHOM7: tty_code_code = 149;
pub const TTYC_KHOM6: tty_code_code = 148;
pub const TTYC_KHOM5: tty_code_code = 147;
pub const TTYC_KHOM4: tty_code_code = 146;
pub const TTYC_KHOM3: tty_code_code = 145;
pub const TTYC_KHOM2: tty_code_code = 144;
pub const TTYC_KF9: tty_code_code = 143;
pub const TTYC_KF8: tty_code_code = 142;
pub const TTYC_KF7: tty_code_code = 141;
pub const TTYC_KF63: tty_code_code = 140;
pub const TTYC_KF62: tty_code_code = 139;
pub const TTYC_KF61: tty_code_code = 138;
pub const TTYC_KF60: tty_code_code = 137;
pub const TTYC_KF6: tty_code_code = 136;
pub const TTYC_KF59: tty_code_code = 135;
pub const TTYC_KF58: tty_code_code = 134;
pub const TTYC_KF57: tty_code_code = 133;
pub const TTYC_KF56: tty_code_code = 132;
pub const TTYC_KF55: tty_code_code = 131;
pub const TTYC_KF54: tty_code_code = 130;
pub const TTYC_KF53: tty_code_code = 129;
pub const TTYC_KF52: tty_code_code = 128;
pub const TTYC_KF51: tty_code_code = 127;
pub const TTYC_KF50: tty_code_code = 126;
pub const TTYC_KF5: tty_code_code = 125;
pub const TTYC_KF49: tty_code_code = 124;
pub const TTYC_KF48: tty_code_code = 123;
pub const TTYC_KF47: tty_code_code = 122;
pub const TTYC_KF46: tty_code_code = 121;
pub const TTYC_KF45: tty_code_code = 120;
pub const TTYC_KF44: tty_code_code = 119;
pub const TTYC_KF43: tty_code_code = 118;
pub const TTYC_KF42: tty_code_code = 117;
pub const TTYC_KF41: tty_code_code = 116;
pub const TTYC_KF40: tty_code_code = 115;
pub const TTYC_KF4: tty_code_code = 114;
pub const TTYC_KF39: tty_code_code = 113;
pub const TTYC_KF38: tty_code_code = 112;
pub const TTYC_KF37: tty_code_code = 111;
pub const TTYC_KF36: tty_code_code = 110;
pub const TTYC_KF35: tty_code_code = 109;
pub const TTYC_KF34: tty_code_code = 108;
pub const TTYC_KF33: tty_code_code = 107;
pub const TTYC_KF32: tty_code_code = 106;
pub const TTYC_KF31: tty_code_code = 105;
pub const TTYC_KF30: tty_code_code = 104;
pub const TTYC_KF3: tty_code_code = 103;
pub const TTYC_KF29: tty_code_code = 102;
pub const TTYC_KF28: tty_code_code = 101;
pub const TTYC_KF27: tty_code_code = 100;
pub const TTYC_KF26: tty_code_code = 99;
pub const TTYC_KF25: tty_code_code = 98;
pub const TTYC_KF24: tty_code_code = 97;
pub const TTYC_KF23: tty_code_code = 96;
pub const TTYC_KF22: tty_code_code = 95;
pub const TTYC_KF21: tty_code_code = 94;
pub const TTYC_KF20: tty_code_code = 93;
pub const TTYC_KF2: tty_code_code = 92;
pub const TTYC_KF19: tty_code_code = 91;
pub const TTYC_KF18: tty_code_code = 90;
pub const TTYC_KF17: tty_code_code = 89;
pub const TTYC_KF16: tty_code_code = 88;
pub const TTYC_KF15: tty_code_code = 87;
pub const TTYC_KF14: tty_code_code = 86;
pub const TTYC_KF13: tty_code_code = 85;
pub const TTYC_KF12: tty_code_code = 84;
pub const TTYC_KF11: tty_code_code = 83;
pub const TTYC_KF10: tty_code_code = 82;
pub const TTYC_KF1: tty_code_code = 81;
pub const TTYC_KEND7: tty_code_code = 80;
pub const TTYC_KEND6: tty_code_code = 79;
pub const TTYC_KEND5: tty_code_code = 78;
pub const TTYC_KEND4: tty_code_code = 77;
pub const TTYC_KEND3: tty_code_code = 76;
pub const TTYC_KEND2: tty_code_code = 75;
pub const TTYC_KEND: tty_code_code = 74;
pub const TTYC_KDN7: tty_code_code = 73;
pub const TTYC_KDN6: tty_code_code = 72;
pub const TTYC_KDN5: tty_code_code = 71;
pub const TTYC_KDN4: tty_code_code = 70;
pub const TTYC_KDN3: tty_code_code = 69;
pub const TTYC_KDN2: tty_code_code = 68;
pub const TTYC_KDCH1: tty_code_code = 67;
pub const TTYC_KDC7: tty_code_code = 66;
pub const TTYC_KDC6: tty_code_code = 65;
pub const TTYC_KDC5: tty_code_code = 64;
pub const TTYC_KDC4: tty_code_code = 63;
pub const TTYC_KDC3: tty_code_code = 62;
pub const TTYC_KDC2: tty_code_code = 61;
pub const TTYC_KCUU1: tty_code_code = 60;
pub const TTYC_KCUF1: tty_code_code = 59;
pub const TTYC_KCUD1: tty_code_code = 58;
pub const TTYC_KCUB1: tty_code_code = 57;
pub const TTYC_KCBT: tty_code_code = 56;
pub const TTYC_INVIS: tty_code_code = 55;
pub const TTYC_INDN: tty_code_code = 54;
pub const TTYC_IL1: tty_code_code = 53;
pub const TTYC_IL: tty_code_code = 52;
pub const TTYC_ICH1: tty_code_code = 51;
pub const TTYC_ICH: tty_code_code = 50;
pub const TTYC_HPA: tty_code_code = 49;
pub const TTYC_HOME: tty_code_code = 48;
pub const TTYC_HLS: tty_code_code = 47;
pub const TTYC_FSL: tty_code_code = 46;
pub const TTYC_ENMG: tty_code_code = 45;
pub const TTYC_ENFCS: tty_code_code = 44;
pub const TTYC_ENEKS: tty_code_code = 43;
pub const TTYC_ENBP: tty_code_code = 42;
pub const TTYC_ENACS: tty_code_code = 41;
pub const TTYC_EL1: tty_code_code = 40;
pub const TTYC_EL: tty_code_code = 39;
pub const TTYC_ED: tty_code_code = 38;
pub const TTYC_ECH: tty_code_code = 37;
pub const TTYC_E3: tty_code_code = 36;
pub const TTYC_DSMG: tty_code_code = 35;
pub const TTYC_DSFCS: tty_code_code = 34;
pub const TTYC_DSEKS: tty_code_code = 33;
pub const TTYC_DSBP: tty_code_code = 32;
pub const TTYC_DL1: tty_code_code = 31;
pub const TTYC_DL: tty_code_code = 30;
pub const TTYC_DIM: tty_code_code = 29;
pub const TTYC_DCH1: tty_code_code = 28;
pub const TTYC_DCH: tty_code_code = 27;
pub const TTYC_CVVIS: tty_code_code = 26;
pub const TTYC_CUU1: tty_code_code = 25;
pub const TTYC_CUU: tty_code_code = 24;
pub const TTYC_CUP: tty_code_code = 23;
pub const TTYC_CUF1: tty_code_code = 22;
pub const TTYC_CUF: tty_code_code = 21;
pub const TTYC_CUD1: tty_code_code = 20;
pub const TTYC_CUD: tty_code_code = 19;
pub const TTYC_CUB1: tty_code_code = 18;
pub const TTYC_CUB: tty_code_code = 17;
pub const TTYC_CSR: tty_code_code = 16;
pub const TTYC_CS: tty_code_code = 15;
pub const TTYC_CR: tty_code_code = 14;
pub const TTYC_COLORS: tty_code_code = 13;
pub const TTYC_CNORM: tty_code_code = 12;
pub const TTYC_CMG: tty_code_code = 11;
pub const TTYC_CLMG: tty_code_code = 10;
pub const TTYC_CLEAR: tty_code_code = 9;
pub const TTYC_CIVIS: tty_code_code = 8;
pub const TTYC_BOLD: tty_code_code = 7;
pub const TTYC_BLINK: tty_code_code = 6;
pub const TTYC_BIDI: tty_code_code = 5;
pub const TTYC_BEL: tty_code_code = 4;
pub const TTYC_BCE: tty_code_code = 3;
pub const TTYC_AX: tty_code_code = 2;
pub const TTYC_AM: tty_code_code = 1;
pub const TTYC_ACSC: tty_code_code = 0;
pub const SCREEN_REDRAW_OUTSIDE: screen_redraw_border_type = 0;
pub type screen_redraw_border_type = u32;
pub const SCREEN_REDRAW_BORDER_BOTTOM: screen_redraw_border_type = 5;
pub const SCREEN_REDRAW_BORDER_TOP: screen_redraw_border_type = 4;
pub const SCREEN_REDRAW_BORDER_RIGHT: screen_redraw_border_type = 3;
pub const SCREEN_REDRAW_BORDER_LEFT: screen_redraw_border_type = 2;
pub const SCREEN_REDRAW_INSIDE: screen_redraw_border_type = 1;
extern "C" fn screen_redraw_border_set(
    mut w: *mut window,
    mut wp: *mut window_pane,
    mut pane_lines: pane_lines,
    mut cell_type: i32,
    mut gc: *mut grid_cell,
) {
    let mut idx: u_int = 0;
    if cell_type == 12 && !(unsafe { (*w).fill_character }).is_null() {
        (unsafe {
            utf8_copy(
                &mut (*gc).data,
                &mut *((*w).fill_character).offset(0 as i32 as isize),
            )
        });
        return;
    }
    match pane_lines as u32 {
        4 => {
            if cell_type == 12 {
                (unsafe { (*gc).attr = ((*gc).attr as i32 | 0x80 as i32) as u_short });
                (unsafe {
                    utf8_set(
                        &mut (*gc).data,
                        (*::core::mem::transmute::<&[u8; 14], &[i8; 14]>(b" xqlkmjwvtun~\0"))
                            [12 as i32 as usize] as u_char,
                    )
                });
            } else {
                (unsafe { (*gc).attr = ((*gc).attr as i32 & !(0x80 as i32)) as u_short });
                if !wp.is_null() && (unsafe { window_pane_index(wp, &mut idx) }) == 0 {
                    (unsafe {
                        utf8_set(
                            &mut (*gc).data,
                            ('0' as i32 as u32).wrapping_add(idx.wrapping_rem(10 as i32 as u32))
                                as u_char,
                        )
                    });
                } else {
                    (unsafe { utf8_set(&mut (*gc).data, '*' as i32 as u_char) });
                }
            }
        }
        1 => {
            (unsafe { (*gc).attr = ((*gc).attr as i32 & !(0x80 as i32)) as u_short });
            (unsafe { utf8_copy(&mut (*gc).data, tty_acs_double_borders(cell_type)) });
        }
        2 => {
            (unsafe { (*gc).attr = ((*gc).attr as i32 & !(0x80 as i32)) as u_short });
            (unsafe { utf8_copy(&mut (*gc).data, tty_acs_heavy_borders(cell_type)) });
        }
        3 => {
            (unsafe { (*gc).attr = ((*gc).attr as i32 & !(0x80 as i32)) as u_short });
            (unsafe {
                utf8_set(
                    &mut (*gc).data,
                    (*::core::mem::transmute::<&[u8; 14], &[i8; 14]>(b" |-+++++++++.\0"))
                        [cell_type as usize] as u_char,
                )
            });
        }
        _ => {
            (unsafe { (*gc).attr = ((*gc).attr as i32 | 0x80 as i32) as u_short });
            (unsafe {
                utf8_set(
                    &mut (*gc).data,
                    (*::core::mem::transmute::<&[u8; 14], &[i8; 14]>(b" xqlkmjwvtun~\0"))
                        [cell_type as usize] as u_char,
                )
            });
        }
    };
}
extern "C" fn screen_redraw_two_panes(mut w: *mut window, mut direction: i32) -> i32 {
    let mut wp: *mut window_pane = std::ptr::null_mut::<window_pane>();
    wp = unsafe { (*(*w).panes.tqh_first).entry.tqe_next };
    if wp.is_null() {
        return 0;
    }
    if !(unsafe { (*wp).entry.tqe_next }).is_null() {
        return 0;
    }
    if direction == 0 && (unsafe { (*wp).xoff }) == 0 as u32 {
        return 0;
    }
    if direction == 1 && (unsafe { (*wp).yoff }) == 0 as u32 {
        return 0;
    }
    return 1;
}
extern "C" fn screen_redraw_pane_border(
    mut ctx: *mut screen_redraw_ctx,
    mut wp: *mut window_pane,
    mut px: u_int,
    mut py: u_int,
) -> screen_redraw_border_type {
    let mut oo: *mut options = unsafe { (*(*wp).window).options };
    let mut ex: u_int = (unsafe { (*wp).xoff }).wrapping_add(unsafe { (*wp).sx });
    let mut ey: u_int = (unsafe { (*wp).yoff }).wrapping_add(unsafe { (*wp).sy });
    let mut hsplit: i32 = 0;
    let mut vsplit: i32 = 0;
    let mut pane_status: i32 = unsafe { (*ctx).pane_status };
    let mut pane_scrollbars: i32 = unsafe { (*ctx).pane_scrollbars };
    let mut sb_w: i32 = 0;
    let mut sb_pos: i32 = unsafe { (*ctx).pane_scrollbars_pos };
    if px >= (unsafe { (*wp).xoff }) && px < ex && py >= (unsafe { (*wp).yoff }) && py < ey {
        return SCREEN_REDRAW_INSIDE;
    }
    match unsafe { options_get_number(oo, b"pane-border-indicators\0" as *const u8 as *const i8) } {
        1 | 3 => {
            hsplit = screen_redraw_two_panes(unsafe { (*wp).window }, 0);
            vsplit = screen_redraw_two_panes(unsafe { (*wp).window }, 1);
        }
        _ => {}
    }
    if (unsafe { window_pane_show_scrollbar(wp, pane_scrollbars) }) != 0 {
        sb_w = (unsafe { (*wp).scrollbar_style.width }) + (unsafe { (*wp).scrollbar_style.pad });
    }
    if ((unsafe { (*wp).yoff }) == 0 as u32
        || py >= (unsafe { (*wp).yoff }).wrapping_sub(1 as i32 as u32))
        && py <= ey
    {
        if sb_pos == 1 {
            if (unsafe { (*wp).xoff }).wrapping_sub(sb_w as u32) == 0 as u32
                && px == (unsafe { (*wp).sx }).wrapping_add(sb_w as u32)
            {
                if !(hsplit != 0 && py > (unsafe { (*wp).sy }).wrapping_div(2 as i32 as u32)) {
                    return SCREEN_REDRAW_BORDER_RIGHT;
                }
            }
            if (unsafe { (*wp).xoff }).wrapping_sub(sb_w as u32) != 0 as u32
                && px
                    == (unsafe { (*wp).xoff })
                        .wrapping_sub(sb_w as u32)
                        .wrapping_sub(1 as i32 as u32)
            {
                if !(hsplit != 0 && py <= (unsafe { (*wp).sy }).wrapping_div(2 as i32 as u32)) {
                    return SCREEN_REDRAW_BORDER_LEFT;
                }
            }
        } else {
            if (unsafe { (*wp).xoff }) == 0 as u32
                && px == (unsafe { (*wp).sx }).wrapping_add(sb_w as u32)
            {
                if !(hsplit != 0 && py > (unsafe { (*wp).sy }).wrapping_div(2 as i32 as u32)) {
                    return SCREEN_REDRAW_BORDER_RIGHT;
                }
            }
            if (unsafe { (*wp).xoff }) != 0 as u32
                && px == (unsafe { (*wp).xoff }).wrapping_sub(1 as i32 as u32)
            {
                if !(hsplit != 0 && py <= (unsafe { (*wp).sy }).wrapping_div(2 as i32 as u32)) {
                    return SCREEN_REDRAW_BORDER_LEFT;
                }
            }
        }
    }
    if vsplit != 0 && pane_status == 0 && sb_w == 0 {
        if (unsafe { (*wp).yoff }) == 0 as u32
            && py == (unsafe { (*wp).sy })
            && px <= (unsafe { (*wp).sx }).wrapping_div(2 as i32 as u32)
        {
            return SCREEN_REDRAW_BORDER_BOTTOM;
        }
        if (unsafe { (*wp).yoff }) != 0 as u32
            && py == (unsafe { (*wp).yoff }).wrapping_sub(1 as i32 as u32)
            && px > (unsafe { (*wp).sx }).wrapping_div(2 as i32 as u32)
        {
            return SCREEN_REDRAW_BORDER_TOP;
        }
    } else if sb_pos == 1 {
        if ((unsafe { (*wp).xoff }).wrapping_sub(sb_w as u32) == 0 as u32
            || px >= (unsafe { (*wp).xoff }).wrapping_sub(sb_w as u32))
            && (px <= ex || sb_w != 0 && px < ex.wrapping_add(sb_w as u32))
        {
            if (unsafe { (*wp).yoff }) != 0 as u32
                && py == (unsafe { (*wp).yoff }).wrapping_sub(1 as i32 as u32)
            {
                return SCREEN_REDRAW_BORDER_TOP;
            }
            if py == ey {
                return SCREEN_REDRAW_BORDER_BOTTOM;
            }
        }
    } else if ((unsafe { (*wp).xoff }) == 0 as u32 || px >= (unsafe { (*wp).xoff }))
        && (px <= ex || sb_w != 0 && px < ex.wrapping_add(sb_w as u32))
    {
        if (unsafe { (*wp).yoff }) != 0 as u32
            && py == (unsafe { (*wp).yoff }).wrapping_sub(1 as i32 as u32)
        {
            return SCREEN_REDRAW_BORDER_TOP;
        }
        if py == ey {
            return SCREEN_REDRAW_BORDER_BOTTOM;
        }
    }
    return SCREEN_REDRAW_OUTSIDE;
}
extern "C" fn screen_redraw_cell_border(
    mut ctx: *mut screen_redraw_ctx,
    mut px: u_int,
    mut py: u_int,
) -> i32 {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut w: *mut window = unsafe { (*(*(*c).session).curw).window };
    let mut wp: *mut window_pane = std::ptr::null_mut::<window_pane>();
    let mut sy: u_int = unsafe { (*w).sy };
    if (unsafe { (*ctx).pane_status }) == 2 {
        sy = sy.wrapping_sub(1);
    }
    if px > (unsafe { (*w).sx }) || py > sy {
        return 0;
    }
    if px == (unsafe { (*w).sx }) || py == sy {
        return 1;
    }
    wp = unsafe { (*w).panes.tqh_first };
    while !wp.is_null() {
        if (unsafe { window_pane_visible(wp) }) != 0 {
            match screen_redraw_pane_border(ctx, wp, px, py) as u32 {
                1 => return 0,
                0 => {}
                _ => return 1,
            }
        }
        wp = unsafe { (*wp).entry.tqe_next };
    }
    return 0;
}
extern "C" fn screen_redraw_type_of_cell(
    mut ctx: *mut screen_redraw_ctx,
    mut px: u_int,
    mut py: u_int,
) -> i32 {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut pane_status: i32 = unsafe { (*ctx).pane_status };
    let mut w: *mut window = unsafe { (*(*(*c).session).curw).window };
    let mut sx: u_int = unsafe { (*w).sx };
    let mut sy: u_int = unsafe { (*w).sy };
    let mut borders: i32 = 0;
    if pane_status == 2 {
        sy = sy.wrapping_sub(1);
    }
    if px > sx || py > sy {
        return 12;
    }
    if px == 0 as u32
        || screen_redraw_cell_border(ctx, px.wrapping_sub(1 as i32 as u32), py) != 0
    {
        borders |= 8;
    }
    if px <= sx && screen_redraw_cell_border(ctx, px.wrapping_add(1 as i32 as u32), py) != 0 {
        borders |= 4;
    }
    if pane_status == 1 {
        if py != 0 as u32
            && screen_redraw_cell_border(ctx, px, py.wrapping_sub(1 as i32 as u32)) != 0
        {
            borders |= 2;
        }
        if screen_redraw_cell_border(ctx, px, py.wrapping_add(1 as i32 as u32)) != 0 {
            borders |= 1;
        }
    } else if pane_status == 2 {
        if py == 0 as u32
            || screen_redraw_cell_border(ctx, px, py.wrapping_sub(1 as i32 as u32)) != 0
        {
            borders |= 2;
        }
        if py != sy && screen_redraw_cell_border(ctx, px, py.wrapping_add(1 as i32 as u32)) != 0 {
            borders |= 1;
        }
    } else {
        if py == 0 as u32
            || screen_redraw_cell_border(ctx, px, py.wrapping_sub(1 as i32 as u32)) != 0
        {
            borders |= 2;
        }
        if screen_redraw_cell_border(ctx, px, py.wrapping_add(1 as i32 as u32)) != 0 {
            borders |= 1;
        }
    }
    match borders {
        15 => return 11,
        14 => return 8,
        13 => return 7,
        12 => return 2,
        11 => return 10,
        10 => return 6,
        9 => return 4,
        7 => return 9,
        6 => return 5,
        5 => return 3,
        3 => return 1,
        _ => {}
    }
    return 12;
}
extern "C" fn screen_redraw_check_cell(
    mut ctx: *mut screen_redraw_ctx,
    mut px: u_int,
    mut py: u_int,
    mut wpp: *mut *mut window_pane,
) -> i32 {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut w: *mut window = unsafe { (*(*(*c).session).curw).window };
    let mut wp: *mut window_pane = std::ptr::null_mut::<window_pane>();
    let mut active: *mut window_pane = std::ptr::null_mut::<window_pane>();
    let mut pane_status: i32 = unsafe { (*ctx).pane_status };
    let mut sx: u_int = unsafe { (*w).sx };
    let mut sy: u_int = unsafe { (*w).sy };
    let mut border: i32 = 0;
    let mut pane_scrollbars: i32 = unsafe { (*ctx).pane_scrollbars };
    let mut right: u_int = 0;
    let mut line: u_int = 0;
    let mut sb_pos: i32 = unsafe { (*ctx).pane_scrollbars_pos };
    let mut sb_w: i32 = 0;
    (unsafe { *wpp = std::ptr::null_mut::<window_pane>() });
    if px > sx || py > sy {
        return 12;
    }
    if px == sx || py == sy {
        return screen_redraw_type_of_cell(ctx, px, py);
    }
    if pane_status != 0 {
        wp = unsafe { server_client_get_pane(c) };
        active = wp;
        loop {
            if (unsafe { window_pane_visible(wp) }) != 0 {
                if pane_status == 1 {
                    line = (unsafe { (*wp).yoff }).wrapping_sub(1 as i32 as u32);
                } else {
                    line = (unsafe { (*wp).yoff }).wrapping_add(sy);
                }
                right = ((unsafe { (*wp).xoff }).wrapping_add(2 as i32 as u32) as u64)
                    .wrapping_add(unsafe { (*wp).status_size })
                    .wrapping_sub(1 as i32 as u64) as u_int;
                if py == line
                    && px >= (unsafe { (*wp).xoff }).wrapping_add(2 as i32 as u32)
                    && px <= right
                {
                    return 0;
                }
            }
            wp = unsafe { (*wp).entry.tqe_next };
            if wp.is_null() {
                wp = unsafe { (*w).panes.tqh_first };
            }
            if wp == active {
                break;
            }
        }
    }
    wp = unsafe { server_client_get_pane(c) };
    active = wp;
    loop {
        if (unsafe { window_pane_visible(wp) }) != 0 {
            (unsafe { *wpp = wp });
            if (unsafe { window_pane_show_scrollbar(wp, pane_scrollbars) }) != 0 {
                if pane_status == 1 {
                    line = (unsafe { (*wp).yoff }).wrapping_sub(1 as i32 as u32);
                } else {
                    line = (unsafe { (*wp).yoff }).wrapping_add(unsafe { (*wp).sy });
                }
                sb_w = (unsafe { (*wp).scrollbar_style.width })
                    + (unsafe { (*wp).scrollbar_style.pad });
                if pane_status != 0 && py != line
                    || (unsafe { (*wp).yoff }) == 0 as u32 && py < (unsafe { (*wp).sy })
                    || py >= (unsafe { (*wp).yoff })
                        && py < (unsafe { (*wp).yoff }).wrapping_add(unsafe { (*wp).sy })
                {
                    if sb_pos == 0
                        && (px >= (unsafe { (*wp).xoff }).wrapping_add(unsafe { (*wp).sx })
                            && px
                                < (unsafe { (*wp).xoff })
                                    .wrapping_add(unsafe { (*wp).sx })
                                    .wrapping_add(sb_w as u32))
                        || sb_pos == 1
                            && (px >= (unsafe { (*wp).xoff }).wrapping_sub(sb_w as u32)
                                && px < (unsafe { (*wp).xoff }))
                    {
                        return 13;
                    }
                }
            }
            border = screen_redraw_pane_border(ctx, wp, px, py) as i32;
            if border == SCREEN_REDRAW_INSIDE as i32 {
                return 0;
            }
            if border != SCREEN_REDRAW_OUTSIDE as i32 {
                return screen_redraw_type_of_cell(ctx, px, py);
            }
        }
        wp = unsafe { (*wp).entry.tqe_next };
        if wp.is_null() {
            wp = unsafe { (*w).panes.tqh_first };
        }
        if wp == active {
            break;
        }
    }
    return 12;
}
extern "C" fn screen_redraw_check_is(
    mut ctx: *mut screen_redraw_ctx,
    mut px: u_int,
    mut py: u_int,
    mut wp: *mut window_pane,
) -> i32 {
    let mut border: screen_redraw_border_type = SCREEN_REDRAW_OUTSIDE;
    border = screen_redraw_pane_border(ctx, wp, px, py);
    if border as u32 != SCREEN_REDRAW_INSIDE as i32 as u32
        && border as u32 != SCREEN_REDRAW_OUTSIDE as i32 as u32
    {
        return 1;
    }
    return 0;
}
extern "C" fn screen_redraw_make_pane_status(
    mut c: *mut client,
    mut wp: *mut window_pane,
    mut rctx: *mut screen_redraw_ctx,
    mut pane_lines: pane_lines,
) -> i32 {
    let mut w: *mut window = unsafe { (*wp).window };
    let mut gc: grid_cell = grid_cell {
        data: utf8_data {
            data: [0; 21],
            have: 0,
            size: 0,
            width: 0,
        },
        attr: 0,
        flags: 0,
        fg: 0,
        bg: 0,
        us: 0,
        link: 0,
    };
    let mut fmt: *const i8 = std::ptr::null::<i8>();
    let mut ft: *mut format_tree = std::ptr::null_mut::<format_tree>();
    let mut expanded: *mut i8 = std::ptr::null_mut::<i8>();
    let mut pane_status: i32 = unsafe { (*rctx).pane_status };
    let mut width: u_int = 0;
    let mut i: u_int = 0;
    let mut cell_type: u_int = 0;
    let mut px: u_int = 0;
    let mut py: u_int = 0;
    let mut ctx: screen_write_ctx = screen_write_ctx {
        wp: std::ptr::null_mut::<window_pane>(),
        s: std::ptr::null_mut::<screen>(),
        flags: 0,
        init_ctx_cb: None,
        arg: std::ptr::null_mut::<()>(),
        item: std::ptr::null_mut::<screen_write_citem>(),
        scrolled: 0,
        bg: 0,
    };
    let mut old: screen = screen {
        title: std::ptr::null_mut::<i8>(),
        path: std::ptr::null_mut::<i8>(),
        titles: std::ptr::null_mut::<screen_titles>(),
        grid: std::ptr::null_mut::<grid>(),
        cx: 0,
        cy: 0,
        cstyle: SCREEN_CURSOR_DEFAULT,
        default_cstyle: SCREEN_CURSOR_DEFAULT,
        ccolour: 0,
        default_ccolour: 0,
        rupper: 0,
        rlower: 0,
        mode: 0,
        default_mode: 0,
        saved_cx: 0,
        saved_cy: 0,
        saved_grid: std::ptr::null_mut::<grid>(),
        saved_cell: grid_cell {
            data: utf8_data {
                data: [0; 21],
                have: 0,
                size: 0,
                width: 0,
            },
            attr: 0,
            flags: 0,
            fg: 0,
            bg: 0,
            us: 0,
            link: 0,
        },
        saved_flags: 0,
        tabs: std::ptr::null_mut::<bitstr_t>(),
        sel: std::ptr::null_mut::<screen_sel>(),
        write_list: std::ptr::null_mut::<screen_write_cline>(),
        hyperlinks: std::ptr::null_mut::<hyperlinks>(),
    };
    ft = unsafe {
        format_create(
            c,
            std::ptr::null_mut::<cmdq_item>(),
            (CLIENT_ACTIVEPANE as u32 | (*wp).id) as i32,
            0x1 as i32,
        )
    };
    (unsafe { format_defaults(ft, c, (*c).session, (*(*c).session).curw, wp) });
    if wp == (unsafe { server_client_get_pane(c) }) {
        (unsafe {
            style_apply(
                &mut gc,
                (*w).options,
                b"pane-active-border-style\0" as *const u8 as *const i8,
                ft,
            )
        });
    } else {
        (unsafe {
            style_apply(
                &mut gc,
                (*w).options,
                b"pane-border-style\0" as *const u8 as *const i8,
                ft,
            )
        });
    }
    fmt = unsafe {
        options_get_string(
            (*wp).options,
            b"pane-border-format\0" as *const u8 as *const i8,
        )
    };
    expanded = unsafe { format_expand_time(ft, fmt) };
    if (unsafe { (*wp).sx }) < 4 as u32 {
        width = 0 as u_int;
        (unsafe { (*wp).status_size = width as size_t });
    } else {
        width = (unsafe { (*wp).sx }).wrapping_sub(4 as i32 as u32);
        (unsafe { (*wp).status_size = width as size_t });
    }
    (unsafe {
        memcpy(
            &mut old as *mut screen as *mut (),
            &mut (*wp).status_screen as *mut screen as *const (),
            ::core::mem::size_of::<screen>() as u64,
        )
    });
    (unsafe {
        screen_init(
            &mut (*wp).status_screen,
            width, 1 as u_int, 0 as u_int,
        )
    });
    (unsafe { (*wp).status_screen.mode = 0 });
    (unsafe { screen_write_start(&mut ctx, &mut (*wp).status_screen) });
    i = 0 as u_int;
    while i < width {
        px = (unsafe { (*wp).xoff })
            .wrapping_add(2 as i32 as u32)
            .wrapping_add(i);
        if pane_status == 1 {
            py = (unsafe { (*wp).yoff }).wrapping_sub(1 as i32 as u32);
        } else {
            py = (unsafe { (*wp).yoff }).wrapping_add(unsafe { (*wp).sy });
        }
        cell_type = screen_redraw_type_of_cell(rctx, px, py) as u_int;
        screen_redraw_border_set(w, wp, pane_lines, cell_type as i32, &mut gc);
        (unsafe { screen_write_cell(&mut ctx, &mut gc) });
        i = i.wrapping_add(1);
    }
    gc.attr = (gc.attr as i32 & !(0x80 as i32)) as u_short;
    (unsafe { screen_write_cursormove(&mut ctx, 0, 0, 0) });
    (unsafe {
        format_draw(
            &mut ctx,
            &mut gc,
            width,
            expanded,
            std::ptr::null_mut::<style_ranges>(), 0,
        )
    });
    (unsafe { screen_write_stop(&mut ctx) });
    (unsafe { free(expanded as *mut ()) });
    (unsafe { format_free(ft) });
    if (unsafe { grid_compare((*wp).status_screen.grid, old.grid) }) == 0 {
        (unsafe { screen_free(&mut old) });
        return 0;
    }
    (unsafe { screen_free(&mut old) });
    return 1;
}
extern "C" fn screen_redraw_draw_pane_status(mut ctx: *mut screen_redraw_ctx) {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut w: *mut window = unsafe { (*(*(*c).session).curw).window };
    let mut tty: *mut tty = unsafe { &mut (*c).tty };
    let mut wp: *mut window_pane = std::ptr::null_mut::<window_pane>();
    let mut s: *mut screen = std::ptr::null_mut::<screen>();
    let mut i: u_int = 0;
    let mut x: u_int = 0;
    let mut width: u_int = 0;
    let mut xoff: u_int = 0;
    let mut yoff: u_int = 0;
    let mut size: u_int = 0;
    (unsafe {
        log_debug(
            b"%s: %s @%u\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 31], &[i8; 31]>(b"screen_redraw_draw_pane_status\0"))
                .as_ptr(),
            (*c).name,
            (*w).id,
        )
    });
    wp = unsafe { (*w).panes.tqh_first };
    while !wp.is_null() {
        if (unsafe { window_pane_visible(wp) }) != 0 {
            s = unsafe { &mut (*wp).status_screen };
            size = (unsafe { (*wp).status_size }) as u_int;
            if (unsafe { (*ctx).pane_status }) == 1 {
                yoff = (unsafe { (*wp).yoff }).wrapping_sub(1 as i32 as u32);
            } else {
                yoff = (unsafe { (*wp).yoff }).wrapping_add(unsafe { (*wp).sy });
            }
            xoff = (unsafe { (*wp).xoff }).wrapping_add(2 as i32 as u32);
            if !(xoff.wrapping_add(size) <= (unsafe { (*ctx).ox })
                || xoff >= (unsafe { (*ctx).ox }).wrapping_add(unsafe { (*ctx).sx })
                || yoff < (unsafe { (*ctx).oy })
                || yoff >= (unsafe { (*ctx).oy }).wrapping_add(unsafe { (*ctx).sy }))
            {
                if xoff >= (unsafe { (*ctx).ox })
                    && xoff.wrapping_add(size)
                        <= (unsafe { (*ctx).ox }).wrapping_add(unsafe { (*ctx).sx })
                {
                    i = 0 as u_int;
                    x = xoff.wrapping_sub(unsafe { (*ctx).ox });
                    width = size;
                } else if xoff < (unsafe { (*ctx).ox })
                    && xoff.wrapping_add(size)
                        > (unsafe { (*ctx).ox }).wrapping_add(unsafe { (*ctx).sx })
                {
                    i = unsafe { (*ctx).ox };
                    x = 0 as u_int;
                    width = unsafe { (*ctx).sx };
                } else if xoff < (unsafe { (*ctx).ox }) {
                    i = (unsafe { (*ctx).ox }).wrapping_sub(xoff);
                    x = 0 as u_int;
                    width = size.wrapping_sub(i);
                } else {
                    i = 0 as u_int;
                    x = xoff.wrapping_sub(unsafe { (*ctx).ox });
                    width = size.wrapping_sub(x);
                }
                if (unsafe { (*ctx).statustop }) != 0 {
                    yoff =
                        (yoff as u32).wrapping_add(unsafe { (*ctx).statuslines }) as u_int as u_int;
                }
                (unsafe {
                    tty_draw_line(
                        tty,
                        s,
                        i, 0 as u_int,
                        width,
                        x,
                        yoff.wrapping_sub((*ctx).oy),
                        &grid_default_cell,
                        std::ptr::null_mut::<colour_palette>(),
                    )
                });
            }
        }
        wp = unsafe { (*wp).entry.tqe_next };
    }
    (unsafe { tty_cursor(tty, 0 as u_int, 0 as u_int) });
}
extern "C" fn screen_redraw_update(
    mut ctx: *mut screen_redraw_ctx,
    mut flags: uint64_t,
) -> uint64_t {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut w: *mut window = unsafe { (*(*(*c).session).curw).window };
    let mut wp: *mut window_pane = std::ptr::null_mut::<window_pane>();
    let mut redraw: i32 = 0;
    let mut lines: pane_lines = PANE_LINES_SINGLE;
    if !(unsafe { (*c).message_string }).is_null() {
        redraw = unsafe { status_message_redraw(c) };
    } else if !(unsafe { (*c).prompt_string }).is_null() {
        redraw = unsafe { status_prompt_redraw(c) };
    } else {
        redraw = unsafe { status_redraw(c) };
    }
    if redraw == 0 && !flags & 0x1000000 as i32 as u64 != 0 {
        flags &= !(0x10 as i32) as u64;
    }
    if unsafe { ((*c).overlay_draw).is_some() } {
        flags |= 0x2000000 as i32 as u64;
    }
    if (unsafe { (*ctx).pane_status }) != 0 {
        lines = unsafe { (*ctx).pane_lines };
        redraw = 0;
        wp = unsafe { (*w).panes.tqh_first };
        while !wp.is_null() {
            if screen_redraw_make_pane_status(c, wp, ctx, lines) != 0 {
                redraw = 1;
            }
            wp = unsafe { (*wp).entry.tqe_next };
        }
        if redraw != 0 {
            flags |= 0x400 as i32 as u64;
        }
    }
    return flags;
}
extern "C" fn screen_redraw_set_context(mut c: *mut client, mut ctx: *mut screen_redraw_ctx) {
    let mut s: *mut session = unsafe { (*c).session };
    let mut oo: *mut options = unsafe { (*s).options };
    let mut w: *mut window = unsafe { (*(*s).curw).window };
    let mut wo: *mut options = unsafe { (*w).options };
    let mut lines: u_int = 0;
    (unsafe {
        memset(
            ctx as *mut (), 0,
            ::core::mem::size_of::<screen_redraw_ctx>() as u64,
        )
    });
    (unsafe { (*ctx).c = c });
    lines = unsafe { status_line_size(c) };
    if !(unsafe { (*c).message_string }).is_null() || !(unsafe { (*c).prompt_string }).is_null() {
        lines = if lines == 0 as u32 { 1 as u32
        } else {
            lines
        };
    }
    if lines != 0 as u32
        && (unsafe { options_get_number(oo, b"status-position\0" as *const u8 as *const i8) })
            == 0 as i64
    {
        (unsafe { (*ctx).statustop = 1 });
    }
    (unsafe { (*ctx).statuslines = lines });
    (unsafe {
        (*ctx).pane_status =
            options_get_number(wo, b"pane-border-status\0" as *const u8 as *const i8) as i32
    });
    (unsafe {
        (*ctx).pane_lines =
            options_get_number(wo, b"pane-border-lines\0" as *const u8 as *const i8) as pane_lines
    });
    (unsafe {
        (*ctx).pane_scrollbars =
            options_get_number(wo, b"pane-scrollbars\0" as *const u8 as *const i8) as i32
    });
    (unsafe {
        (*ctx).pane_scrollbars_pos =
            options_get_number(wo, b"pane-scrollbars-position\0" as *const u8 as *const i8) as i32
    });
    (unsafe {
        tty_window_offset(
            &mut (*c).tty,
            &mut (*ctx).ox,
            &mut (*ctx).oy,
            &mut (*ctx).sx,
            &mut (*ctx).sy,
        )
    });
    (unsafe {
        log_debug(
            b"%s: %s @%u ox=%u oy=%u sx=%u sy=%u %u/%d\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 26], &[i8; 26]>(b"screen_redraw_set_context\0"))
                .as_ptr(),
            (*c).name,
            (*w).id,
            (*ctx).ox,
            (*ctx).oy,
            (*ctx).sx,
            (*ctx).sy,
            (*ctx).statuslines,
            (*ctx).statustop,
        )
    });
}
#[no_mangle]
pub extern "C" fn screen_redraw_screen(mut c: *mut client) {
    let mut ctx: screen_redraw_ctx = screen_redraw_ctx {
        c: std::ptr::null_mut::<client>(),
        statuslines: 0,
        statustop: 0,
        pane_status: 0,
        pane_lines: PANE_LINES_SINGLE,
        pane_scrollbars: 0,
        pane_scrollbars_pos: 0,
        no_pane_gc: grid_cell {
            data: utf8_data {
                data: [0; 21],
                have: 0,
                size: 0,
                width: 0,
            },
            attr: 0,
            flags: 0,
            fg: 0,
            bg: 0,
            us: 0,
            link: 0,
        },
        no_pane_gc_set: 0,
        sx: 0,
        sy: 0,
        ox: 0,
        oy: 0,
    };
    let mut flags: uint64_t = 0;
    if (unsafe { (*c).flags }) & 0x40 as i32 as u64 != 0 {
        return;
    }
    screen_redraw_set_context(c, &mut ctx);
    flags = screen_redraw_update(&mut ctx, unsafe { (*c).flags });
    if flags as u64
        & ((0x8 as i32
            | 0x10 as i32
            | 0x1000000 as i32
            | 0x400 as i32
            | 0x2000000 as i32
            | KEYC_VI as i32) as u64
            | KEYC_SENT00 as u64)
        == 0 as u64
    {
        return;
    }
    (unsafe { tty_sync_start(&mut (*c).tty) });
    (unsafe { tty_update_mode(&mut (*c).tty, (*c).tty.mode, std::ptr::null_mut::<screen>()) });
    if flags & (0x8 as i32 | 0x400 as i32) as u64 != 0 {
        (unsafe {
            log_debug(
                b"%s: redrawing borders\0" as *const u8 as *const i8,
                (*c).name,
            )
        });
        screen_redraw_draw_borders(&mut ctx);
        if ctx.pane_status != 0 {
            screen_redraw_draw_pane_status(&mut ctx);
        }
        screen_redraw_draw_pane_scrollbars(&mut ctx);
    }
    if flags & 0x8 as i32 as u64 != 0 {
        (unsafe {
            log_debug(
                b"%s: redrawing panes\0" as *const u8 as *const i8,
                (*c).name,
            )
        });
        screen_redraw_draw_panes(&mut ctx);
        screen_redraw_draw_pane_scrollbars(&mut ctx);
    }
    if ctx.statuslines != 0 as u32 && flags & (0x10 as i32 | 0x1000000 as i32) as u64 != 0 {
        (unsafe {
            log_debug(
                b"%s: redrawing status\0" as *const u8 as *const i8,
                (*c).name,
            )
        });
        screen_redraw_draw_status(&mut ctx);
    }
    if (unsafe { ((*c).overlay_draw).is_some() }) && flags & 0x2000000 as i32 as u64 != 0 {
        (unsafe {
            log_debug(
                b"%s: redrawing overlay\0" as *const u8 as *const i8,
                (*c).name,
            )
        });
        (unsafe {
            ((*c).overlay_draw).expect("non-null function pointer")(c, (*c).overlay_data, &mut ctx)
        });
    }
    (unsafe { tty_reset(&mut (*c).tty) });
}
#[no_mangle]
pub extern "C" fn screen_redraw_pane(
    mut c: *mut client,
    mut wp: *mut window_pane,
    mut redraw_scrollbar_only: i32,
) {
    let mut ctx: screen_redraw_ctx = screen_redraw_ctx {
        c: std::ptr::null_mut::<client>(),
        statuslines: 0,
        statustop: 0,
        pane_status: 0,
        pane_lines: PANE_LINES_SINGLE,
        pane_scrollbars: 0,
        pane_scrollbars_pos: 0,
        no_pane_gc: grid_cell {
            data: utf8_data {
                data: [0; 21],
                have: 0,
                size: 0,
                width: 0,
            },
            attr: 0,
            flags: 0,
            fg: 0,
            bg: 0,
            us: 0,
            link: 0,
        },
        no_pane_gc_set: 0,
        sx: 0,
        sy: 0,
        ox: 0,
        oy: 0,
    };
    if (unsafe { window_pane_visible(wp) }) == 0 {
        return;
    }
    screen_redraw_set_context(c, &mut ctx);
    (unsafe { tty_sync_start(&mut (*c).tty) });
    (unsafe { tty_update_mode(&mut (*c).tty, (*c).tty.mode, std::ptr::null_mut::<screen>()) });
    if redraw_scrollbar_only == 0 {
        screen_redraw_draw_pane(&mut ctx, wp);
    }
    if (unsafe { window_pane_show_scrollbar(wp, ctx.pane_scrollbars) }) != 0 {
        screen_redraw_draw_pane_scrollbar(&mut ctx, wp);
    }
    (unsafe { tty_reset(&mut (*c).tty) });
}
extern "C" fn screen_redraw_draw_borders_style(
    mut ctx: *mut screen_redraw_ctx,
    mut x: u_int,
    mut y: u_int,
    mut wp: *mut window_pane,
) -> *const grid_cell {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut s: *mut session = unsafe { (*c).session };
    let mut w: *mut window = unsafe { (*(*s).curw).window };
    let mut active: *mut window_pane = unsafe { server_client_get_pane(c) };
    let mut oo: *mut options = unsafe { (*w).options };
    let mut ft: *mut format_tree = std::ptr::null_mut::<format_tree>();
    if (unsafe { (*wp).border_gc_set }) != 0 {
        return unsafe { &mut (*wp).border_gc };
    }
    (unsafe { (*wp).border_gc_set = 1 });
    ft = unsafe { format_create_defaults(std::ptr::null_mut::<cmdq_item>(), c, s, (*s).curw, wp) };
    if screen_redraw_check_is(ctx, x, y, active) != 0 {
        (unsafe {
            style_apply(
                &mut (*wp).border_gc,
                oo,
                b"pane-active-border-style\0" as *const u8 as *const i8,
                ft,
            )
        });
    } else {
        (unsafe {
            style_apply(
                &mut (*wp).border_gc,
                oo,
                b"pane-border-style\0" as *const u8 as *const i8,
                ft,
            )
        });
    }
    (unsafe { format_free(ft) });
    return unsafe { &mut (*wp).border_gc };
}
extern "C" fn screen_redraw_draw_borders_cell(
    mut ctx: *mut screen_redraw_ctx,
    mut i: u_int,
    mut j: u_int,
) {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut s: *mut session = unsafe { (*c).session };
    let mut w: *mut window = unsafe { (*(*s).curw).window };
    let mut oo: *mut options = unsafe { (*w).options };
    let mut tty: *mut tty = unsafe { &mut (*c).tty };
    let mut ft: *mut format_tree = std::ptr::null_mut::<format_tree>();
    let mut wp: *mut window_pane = std::ptr::null_mut::<window_pane>();
    let mut active: *mut window_pane = unsafe { server_client_get_pane(c) };
    let mut gc: grid_cell = grid_cell {
        data: utf8_data {
            data: [0; 21],
            have: 0,
            size: 0,
            width: 0,
        },
        attr: 0,
        flags: 0,
        fg: 0,
        bg: 0,
        us: 0,
        link: 0,
    };
    let mut tmp: *const grid_cell = std::ptr::null::<grid_cell>();
    let mut r: overlay_ranges = overlay_ranges {
        px: [0; 3],
        nx: [0; 3],
    };
    let mut cell_type: u_int = 0;
    let mut x: u_int = (unsafe { (*ctx).ox }).wrapping_add(i);
    let mut y: u_int = (unsafe { (*ctx).oy }).wrapping_add(j);
    let mut arrows: i32 = 0;
    let mut border: i32 = 0;
    let mut isolates: i32 = 0;
    if unsafe { ((*c).overlay_check).is_some() } {
        (unsafe {
            ((*c).overlay_check).expect("non-null function pointer")(
                c,
                (*c).overlay_data,
                x,
                y, 1 as u_int,
                &mut r,
            )
        });
        if (r.nx[0 as i32 as usize]).wrapping_add(r.nx[1 as i32 as usize]) == 0 as u32 {
            return;
        }
    }
    cell_type = screen_redraw_check_cell(ctx, x, y, &mut wp) as u_int;
    if cell_type == 0 as u32 || cell_type == 13 as u32 {
        return;
    }
    if wp.is_null() {
        if (unsafe { (*ctx).no_pane_gc_set }) == 0 {
            ft = unsafe {
                format_create_defaults(
                    std::ptr::null_mut::<cmdq_item>(),
                    c,
                    s,
                    (*s).curw,
                    std::ptr::null_mut::<window_pane>(),
                )
            };
            (unsafe {
                memcpy(
                    &mut (*ctx).no_pane_gc as *mut grid_cell as *mut (),
                    &grid_default_cell as *const grid_cell as *const (),
                    ::core::mem::size_of::<grid_cell>() as u64,
                )
            });
            (unsafe {
                style_add(
                    &mut (*ctx).no_pane_gc,
                    oo,
                    b"pane-border-style\0" as *const u8 as *const i8,
                    ft,
                )
            });
            (unsafe { format_free(ft) });
            (unsafe { (*ctx).no_pane_gc_set = 1 });
        }
        (unsafe {
            memcpy(
                &mut gc as *mut grid_cell as *mut (),
                &mut (*ctx).no_pane_gc as *mut grid_cell as *const (),
                ::core::mem::size_of::<grid_cell>() as u64,
            )
        });
    } else {
        tmp = screen_redraw_draw_borders_style(ctx, x, y, wp);
        if tmp.is_null() {
            return;
        }
        (unsafe {
            memcpy(
                &mut gc as *mut grid_cell as *mut (),
                tmp as *const (),
                ::core::mem::size_of::<grid_cell>() as u64,
            )
        });
        if (unsafe { server_is_marked(s, (*s).curw, marked_pane.wp) }) != 0
            && screen_redraw_check_is(ctx, x, y, unsafe { marked_pane.wp }) != 0
        {
            gc.attr = (gc.attr as i32 ^ 0x10 as i32) as u_short;
        }
    }
    screen_redraw_border_set(
        w,
        wp,
        unsafe { (*ctx).pane_lines },
        cell_type as i32,
        &mut gc,
    );
    if cell_type == 1 as u32
        && (unsafe { (*c).flags }) & 0x10000 as i32 as u64 != 0
        && (unsafe { tty_term_has((*tty).term, TTYC_BIDI) }) != 0
    {
        isolates = 1;
    } else {
        isolates = 0;
    }
    if (unsafe { (*ctx).statustop }) != 0 {
        (unsafe { tty_cursor(tty, i, ((*ctx).statuslines).wrapping_add(j)) });
    } else {
        (unsafe { tty_cursor(tty, i, j) });
    }
    if isolates != 0 {
        (unsafe { tty_puts(tty, b"\xE2\x81\xA9\0" as *const u8 as *const i8) });
    }
    match unsafe { options_get_number(oo, b"pane-border-indicators\0" as *const u8 as *const i8) } {
        2 | 3 => {
            arrows = 1;
        }
        _ => {}
    }
    if !wp.is_null() && arrows != 0 {
        border = screen_redraw_pane_border(ctx, active, x, y) as i32;
        if (i == (unsafe { (*wp).xoff }).wrapping_add(1 as i32 as u32)
            && (cell_type == 2 as u32
                || cell_type == 7 as u32 && border == SCREEN_REDRAW_BORDER_BOTTOM as i32
                || cell_type == 8 as u32 && border == SCREEN_REDRAW_BORDER_TOP as i32)
            || j == (unsafe { (*wp).yoff }).wrapping_add(1 as i32 as u32)
                && (cell_type == 1 as u32
                    || cell_type == 9 as u32 && border == SCREEN_REDRAW_BORDER_RIGHT as i32
                    || cell_type == 10 as u32 && border == SCREEN_REDRAW_BORDER_LEFT as i32))
            && screen_redraw_check_is(ctx, x, y, active) != 0
        {
            gc.attr = (gc.attr as i32 | 0x80 as i32) as u_short;
            (unsafe {
                utf8_set(
                    &mut gc.data,
                    (*::core::mem::transmute::<&[u8; 7], &[i8; 7]>(b"  +,.-\0"))[border as usize]
                        as u_char,
                )
            });
        }
    }
    (unsafe {
        tty_cell(
            tty,
            &mut gc,
            &grid_default_cell,
            std::ptr::null_mut::<colour_palette>(),
            std::ptr::null_mut::<hyperlinks>(),
        )
    });
    if isolates != 0 {
        (unsafe { tty_puts(tty, b"\xE2\x81\xA6\0" as *const u8 as *const i8) });
    }
}
extern "C" fn screen_redraw_draw_borders(mut ctx: *mut screen_redraw_ctx) {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut s: *mut session = unsafe { (*c).session };
    let mut w: *mut window = unsafe { (*(*s).curw).window };
    let mut wp: *mut window_pane = std::ptr::null_mut::<window_pane>();
    let mut i: u_int = 0;
    let mut j: u_int = 0;
    (unsafe {
        log_debug(
            b"%s: %s @%u\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 27], &[i8; 27]>(b"screen_redraw_draw_borders\0"))
                .as_ptr(),
            (*c).name,
            (*w).id,
        )
    });
    wp = unsafe { (*w).panes.tqh_first };
    while !wp.is_null() {
        (unsafe { (*wp).border_gc_set = 0 });
        wp = unsafe { (*wp).entry.tqe_next };
    }
    j = 0 as u_int;
    while j < (unsafe { (*c).tty.sy }).wrapping_sub(unsafe { (*ctx).statuslines }) {
        i = 0 as u_int;
        while i < (unsafe { (*c).tty.sx }) {
            screen_redraw_draw_borders_cell(ctx, i, j);
            i = i.wrapping_add(1);
        }
        j = j.wrapping_add(1);
    }
}
extern "C" fn screen_redraw_draw_panes(mut ctx: *mut screen_redraw_ctx) {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut w: *mut window = unsafe { (*(*(*c).session).curw).window };
    let mut wp: *mut window_pane = std::ptr::null_mut::<window_pane>();
    (unsafe {
        log_debug(
            b"%s: %s @%u\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 25], &[i8; 25]>(b"screen_redraw_draw_panes\0"))
                .as_ptr(),
            (*c).name,
            (*w).id,
        )
    });
    wp = unsafe { (*w).panes.tqh_first };
    while !wp.is_null() {
        if (unsafe { window_pane_visible(wp) }) != 0 {
            screen_redraw_draw_pane(ctx, wp);
        }
        wp = unsafe { (*wp).entry.tqe_next };
    }
}
extern "C" fn screen_redraw_draw_status(mut ctx: *mut screen_redraw_ctx) {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut w: *mut window = unsafe { (*(*(*c).session).curw).window };
    let mut tty: *mut tty = unsafe { &mut (*c).tty };
    let mut s: *mut screen = unsafe { (*c).status.active };
    let mut i: u_int = 0;
    let mut y: u_int = 0;
    (unsafe {
        log_debug(
            b"%s: %s @%u\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 26], &[i8; 26]>(b"screen_redraw_draw_status\0"))
                .as_ptr(),
            (*c).name,
            (*w).id,
        )
    });
    if (unsafe { (*ctx).statustop }) != 0 {
        y = 0 as u_int;
    } else {
        y = (unsafe { (*c).tty.sy }).wrapping_sub(unsafe { (*ctx).statuslines });
    }
    i = 0 as u_int;
    while i < (unsafe { (*ctx).statuslines }) {
        (unsafe {
            tty_draw_line(
                tty,
                s, 0 as u_int,
                i,
                (2147483647 as i32 as u32)
                    .wrapping_mul(2 as u32)
                    .wrapping_add(1 as u32), 0 as u_int,
                y.wrapping_add(i),
                &grid_default_cell,
                std::ptr::null_mut::<colour_palette>(),
            )
        });
        i = i.wrapping_add(1);
    }
}
extern "C" fn screen_redraw_draw_pane(mut ctx: *mut screen_redraw_ctx, mut wp: *mut window_pane) {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut w: *mut window = unsafe { (*(*(*c).session).curw).window };
    let mut tty: *mut tty = unsafe { &mut (*c).tty };
    let mut s: *mut screen = unsafe { (*wp).screen };
    let mut palette: *mut colour_palette = unsafe { &mut (*wp).palette };
    let mut defaults: grid_cell = grid_cell {
        data: utf8_data {
            data: [0; 21],
            have: 0,
            size: 0,
            width: 0,
        },
        attr: 0,
        flags: 0,
        fg: 0,
        bg: 0,
        us: 0,
        link: 0,
    };
    let mut i: u_int = 0;
    let mut j: u_int = 0;
    let mut top: u_int = 0;
    let mut x: u_int = 0;
    let mut y: u_int = 0;
    let mut width: u_int = 0;
    (unsafe {
        log_debug(
            b"%s: %s @%u %%%u\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 24], &[i8; 24]>(b"screen_redraw_draw_pane\0"))
                .as_ptr(),
            (*c).name,
            (*w).id,
            (*wp).id,
        )
    });
    if (unsafe { (*wp).xoff }).wrapping_add(unsafe { (*wp).sx }) <= (unsafe { (*ctx).ox })
        || (unsafe { (*wp).xoff }) >= (unsafe { (*ctx).ox }).wrapping_add(unsafe { (*ctx).sx })
    {
        return;
    }
    if (unsafe { (*ctx).statustop }) != 0 {
        top = unsafe { (*ctx).statuslines };
    } else {
        top = 0 as u_int;
    }
    j = 0 as u_int;
    while j < (unsafe { (*wp).sy }) {
        if !((unsafe { (*wp).yoff }).wrapping_add(j) < (unsafe { (*ctx).oy })
            || (unsafe { (*wp).yoff }).wrapping_add(j)
                >= (unsafe { (*ctx).oy }).wrapping_add(unsafe { (*ctx).sy }))
        {
            y = top
                .wrapping_add(unsafe { (*wp).yoff })
                .wrapping_add(j)
                .wrapping_sub(unsafe { (*ctx).oy });
            if (unsafe { (*wp).xoff }) >= (unsafe { (*ctx).ox })
                && (unsafe { (*wp).xoff }).wrapping_add(unsafe { (*wp).sx })
                    <= (unsafe { (*ctx).ox }).wrapping_add(unsafe { (*ctx).sx })
            {
                i = 0 as u_int;
                x = (unsafe { (*wp).xoff }).wrapping_sub(unsafe { (*ctx).ox });
                width = unsafe { (*wp).sx };
            } else if (unsafe { (*wp).xoff }) < (unsafe { (*ctx).ox })
                && (unsafe { (*wp).xoff }).wrapping_add(unsafe { (*wp).sx })
                    > (unsafe { (*ctx).ox }).wrapping_add(unsafe { (*ctx).sx })
            {
                i = unsafe { (*ctx).ox };
                x = 0 as u_int;
                width = unsafe { (*ctx).sx };
            } else if (unsafe { (*wp).xoff }) < (unsafe { (*ctx).ox }) {
                i = (unsafe { (*ctx).ox }).wrapping_sub(unsafe { (*wp).xoff });
                x = 0 as u_int;
                width = (unsafe { (*wp).sx }).wrapping_sub(i);
            } else {
                i = 0 as u_int;
                x = (unsafe { (*wp).xoff }).wrapping_sub(unsafe { (*ctx).ox });
                width = (unsafe { (*ctx).sx }).wrapping_sub(x);
            }
            (unsafe {
                log_debug(
                    b"%s: %s %%%u line %u,%u at %u,%u, width %u\0" as *const u8 as *const i8,
                    (*::core::mem::transmute::<&[u8; 24], &[i8; 24]>(b"screen_redraw_draw_pane\0"))
                        .as_ptr(),
                    (*c).name,
                    (*wp).id,
                    i,
                    j,
                    x,
                    y,
                    width,
                )
            });
            (unsafe { tty_default_colours(&mut defaults, wp) });
            (unsafe { tty_draw_line(tty, s, i, j, width, x, y, &mut defaults, palette) });
        }
        j = j.wrapping_add(1);
    }
}
extern "C" fn screen_redraw_draw_pane_scrollbars(mut ctx: *mut screen_redraw_ctx) {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut w: *mut window = unsafe { (*(*(*c).session).curw).window };
    let mut wp: *mut window_pane = std::ptr::null_mut::<window_pane>();
    (unsafe {
        log_debug(
            b"%s: %s @%u\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 35], &[i8; 35]>(
                b"screen_redraw_draw_pane_scrollbars\0",
            ))
            .as_ptr(),
            (*c).name,
            (*w).id,
        )
    });
    wp = unsafe { (*w).panes.tqh_first };
    while !wp.is_null() {
        if (unsafe { window_pane_show_scrollbar(wp, (*ctx).pane_scrollbars) }) != 0
            && (unsafe { window_pane_visible(wp) }) != 0
        {
            screen_redraw_draw_pane_scrollbar(ctx, wp);
        }
        wp = unsafe { (*wp).entry.tqe_next };
    }
}
extern "C" fn screen_redraw_draw_pane_scrollbar(
    mut ctx: *mut screen_redraw_ctx,
    mut wp: *mut window_pane,
) {
    let mut s: *mut screen = unsafe { (*wp).screen };
    let mut percent_view: f64 = 0.;
    let mut sb: u_int = (unsafe { (*ctx).pane_scrollbars }) as u_int;
    let mut total_height: u_int = 0;
    let mut sb_h: u_int = unsafe { (*wp).sy };
    let mut sb_pos: u_int = (unsafe { (*ctx).pane_scrollbars_pos }) as u_int;
    let mut slider_h: u_int = 0;
    let mut slider_y: u_int = 0;
    let mut sb_w: i32 = unsafe { (*wp).scrollbar_style.width };
    let mut sb_pad: i32 = unsafe { (*wp).scrollbar_style.pad };
    let mut cm_y: i32 = 0;
    let mut cm_size: i32 = 0;
    let mut xoff: i32 = (unsafe { (*wp).xoff }) as i32;
    let mut ox: i32 = (unsafe { (*ctx).ox }) as i32;
    let mut sb_x: i32 = 0;
    let mut sb_y: i32 = (unsafe { (*wp).yoff }).wrapping_sub(unsafe { (*ctx).oy }) as i32;
    if (unsafe { window_pane_mode(wp) }) == 0 {
        if sb == 1 as u32 {
            return;
        }
        total_height = (unsafe { (*(*s).grid).sy }).wrapping_add(unsafe { (*(*s).grid).hsize });
        percent_view = sb_h as f64 / total_height as f64;
        slider_h = (sb_h as f64 * percent_view) as u_int;
        slider_y = sb_h.wrapping_sub(slider_h);
    } else {
        if (unsafe { (*wp).modes.tqh_first }).is_null() {
            return;
        }
        if (unsafe {
            window_copy_get_current_offset(
                wp,
                &mut cm_y as *mut i32 as *mut u_int,
                &mut cm_size as *mut i32 as *mut u_int,
            )
        }) == 0
        {
            return;
        }
        total_height = (cm_size as u32).wrapping_add(sb_h);
        percent_view = sb_h as f64 / (cm_size as u32).wrapping_add(sb_h) as f64;
        slider_h = (sb_h as f64 * percent_view) as u_int;
        slider_y = (sb_h.wrapping_add(1 as i32 as u32) as f64 * (cm_y as f64 / total_height as f64))
            as u_int;
    }
    if sb_pos == 1 as u32 {
        sb_x = xoff - sb_w - sb_pad - ox;
    } else {
        sb_x = (xoff as u32)
            .wrapping_add(unsafe { (*wp).sx })
            .wrapping_sub(ox as u32) as i32;
    }
    if slider_h < 1 as u32 {
        slider_h = 1 as u_int;
    }
    if slider_y >= sb_h {
        slider_y = sb_h.wrapping_sub(1 as i32 as u32);
    }
    screen_redraw_draw_scrollbar(ctx, wp, sb_pos as i32, sb_x, sb_y, sb_h, slider_h, slider_y);
    (unsafe { (*wp).sb_slider_y = slider_y });
    (unsafe { (*wp).sb_slider_h = slider_h });
}
extern "C" fn screen_redraw_draw_scrollbar(
    mut ctx: *mut screen_redraw_ctx,
    mut wp: *mut window_pane,
    mut sb_pos: i32,
    mut sb_x: i32,
    mut sb_y: i32,
    mut sb_h: u_int,
    mut slider_h: u_int,
    mut slider_y: u_int,
) {
    let mut c: *mut client = unsafe { (*ctx).c };
    let mut tty: *mut tty = unsafe { &mut (*c).tty };
    let mut gc: grid_cell = grid_cell {
        data: utf8_data {
            data: [0; 21],
            have: 0,
            size: 0,
            width: 0,
        },
        attr: 0,
        flags: 0,
        fg: 0,
        bg: 0,
        us: 0,
        link: 0,
    };
    let mut slgc: grid_cell = grid_cell {
        data: utf8_data {
            data: [0; 21],
            have: 0,
            size: 0,
            width: 0,
        },
        attr: 0,
        flags: 0,
        fg: 0,
        bg: 0,
        us: 0,
        link: 0,
    };
    let mut gcp: *mut grid_cell = std::ptr::null_mut::<grid_cell>();
    let mut sb_style: *mut style = unsafe { &mut (*wp).scrollbar_style };
    let mut i: u_int = 0;
    let mut j: u_int = 0;
    let mut imax: u_int = 0;
    let mut jmax: u_int = 0;
    let mut sb_w: u_int = (unsafe { (*sb_style).width }) as u_int;
    let mut sb_pad: u_int = (unsafe { (*sb_style).pad }) as u_int;
    let mut px: i32 = 0;
    let mut py: i32 = 0;
    let mut ox: i32 = (unsafe { (*ctx).ox }) as i32;
    let mut oy: i32 = (unsafe { (*ctx).oy }) as i32;
    let mut sx: i32 = (unsafe { (*ctx).sx }) as i32;
    let mut sy: i32 = (unsafe { (*ctx).sy }) as i32;
    let mut xoff: i32 = (unsafe { (*wp).xoff }) as i32;
    let mut yoff: i32 = (unsafe { (*wp).yoff }) as i32;
    gc = unsafe { (*sb_style).gc };
    (unsafe {
        memcpy(
            &mut slgc as *mut grid_cell as *mut (),
            &mut gc as *mut grid_cell as *const (),
            ::core::mem::size_of::<grid_cell>() as u64,
        )
    });
    slgc.fg = gc.bg;
    slgc.bg = gc.fg;
    imax = sb_w.wrapping_add(sb_pad);
    if imax as i32 + sb_x > sx {
        imax = (sx - sb_x) as u_int;
    }
    jmax = sb_h;
    if jmax as i32 + sb_y > sy {
        jmax = (sy - sb_y) as u_int;
    }
    j = 0 as u_int;
    while j < jmax {
        py = (sb_y as u32).wrapping_add(j) as i32;
        i = 0 as u_int;
        while i < imax {
            px = (sb_x as u32).wrapping_add(i) as i32;
            if !(px < xoff - ox - sb_w as i32 - sb_pad as i32
                || px >= sx
                || px < 0
                || py < yoff - oy - 1
                || py >= sy
                || py < 0)
            {
                (unsafe { tty_cursor(tty, px as u_int, py as u_int) });
                if sb_pos == 1 && i >= sb_w && i < sb_w.wrapping_add(sb_pad)
                    || sb_pos == 0 && i < sb_pad
                {
                    (unsafe {
                        tty_cell(
                            tty,
                            &grid_default_cell,
                            &grid_default_cell,
                            std::ptr::null_mut::<colour_palette>(),
                            std::ptr::null_mut::<hyperlinks>(),
                        )
                    });
                } else {
                    if j >= slider_y && j < slider_y.wrapping_add(slider_h) {
                        gcp = &mut slgc;
                    } else {
                        gcp = &mut gc;
                    }
                    (unsafe {
                        tty_cell(
                            tty,
                            gcp,
                            &grid_default_cell,
                            std::ptr::null_mut::<colour_palette>(),
                            std::ptr::null_mut::<hyperlinks>(),
                        )
                    });
                }
            }
            i = i.wrapping_add(1);
        }
        j = j.wrapping_add(1);
    }
}
